![[转载]第一天 <wbr>午夜倒数《苹果iOS实例编程入门教程》 [转载]第一天 <wbr>午夜倒数《苹果iOS实例编程入门教程》](https://i-blog.csdnimg.cn/blog_migrate/a4c26d1e5885305701be709a3d33442f.gif)
现在已经改为:sdk4.2版本。
首先运行以安装好的 xCode
选择: File->New Project.
从 "New Project" 窗口
选择 : iPhone OS ->Applications-> View-Based Application
命名 : 我这里命名为 "minutesToMidnight"
(1)
(红色为所添加的代码)
#import <UIKit/UIKit.h>
@interface minutesToMidnightViewCon
}
@property(nonatomic,retain)
@property (nonatomic, retain) NSTimer *timer;
-(void)onTimer;
@end
(2)
#import "minutesToMidnightViewCon
@implementation minutesToMidnightViewCon
@synthesize timer;
@synthesize countdownLabel;
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
}
-(void)onTimer{
}
- (void)didReceiveMemoryWarning {
}
- (void)viewDidUnload {
}
- (void)dealloc {
}
@end
完成后打开Interface Builder,进行UIView设置
(3) UIView 界面设置
- 黑色背景,红色字体,让它看起来像一个闹钟。
双击文件: "MinutesToMidnightViewCon
然后 "Interface Builder"
选择: Tools -> Reveal In Document Window -> View
选择:
在色条内选择 "黑色",可以看到背景变为黑色
(4) 加入 UILabel 显示我们的倒数时间
选择: Tools -> Library ; 从Library显示菜单中拖拉一个 Label 到 Main View
在主显示上点击 Label;从Label Attributes 上选着字体的颜色和字体大小。
(5)从 Interface Builder 写入 UILabel 的 class file
再打开SDK工具 Interface Builder
在主视窗口或文件窗口;点击 Label
选择: Tools -> Connection Inspector
移动鼠标在"New Referencing Outlet" 后面圆圈上; 圆圈变为(+); 拖向直线连接到"File's Owner";
放开鼠标选择键出现 "countdownLabel"; 选上它。
选择: File -> Save then close Interface Builde
最后在 xCode 选择 Build->Build and Go
下载今天程序文件:
文章本人经过修改及测试,希望大家多多交流。欢迎转载,但请注明出处,多珍惜别人的劳动成果,谢谢大家。
一切版权归http://blog.sina.com.cn/iphonesdk
更多关于iPhone编程的内容可以参阅下书,
链接:![]()