实例iPhone SDK 编程入门教程.doc
《实例iPhone SDK 编程入门教程.doc》由会员分享,可在线阅读,更多相关《实例iPhone SDK 编程入门教程.doc(86页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、实例iPhoneSDK编程入门教程-第一天DAY ONE - MinutesToMidnight大家一起来建立我们的第一个 iPhone app,给你的iPhone计算离午夜12:00点的剩余时间。首先运行以安装好的 xCode选择: File-New Project.从 New Project 窗口选择 : iPhone OS -Applications- View-Based Application命名 : 我这里命名为 MinutesToMidnight(1) UIView 界面设置- 黑色背景,红色字体,让它看起来像一个闹钟。双击文件: MinutesToMidnightViewCon
2、troller.xib ;然后 Interface Builder 会自动打开,在这里我们可以编辑改变界面选择: Tools - Reveal In Document Window - View选择: Tools - Attributes Inspector在色条内选择 黑色,可以看到背景变为黑色(2) 加入 UILabel 显示我们的倒数时间选择: Tools - Library ; 从Library显示菜单中拖拉一个 Label 到 Main View在主显示上点击 Label;从Label Attributes 上选着字体的颜色和字体大小。(3) 把界面文件更新到我们的代码文件上面在Mi
3、nutesToMidnightViewController.xib文件窗口, 选择: Files Owner (这步很关键,我在第一次编辑时没成功就因为忘了这一步)选择: Tools-Idenity Inspector在 Idenity inspector 中间 Class Outlets 按 +;把 myOutlet1 改为 countdownLabel;把 id 改为 UILabel; 按回车,确定已更改。(4) 写入MinutesToMidnightViewController.h 和 MinutesToMidnightViewController.m确认还在MinutesToMidni
4、ghtViewController.xib文件窗口, 选择: Files Owner选择: File-Write Class Files在 Save As: MinutesToMidnightViewController点击: Save点击: Merge在右下角 Actions 按下选 (bottom right) Select Left点击: 上方红色小圈关闭窗口点击: Save关闭所有 merge 窗口打开 xCode; 选择 Build-Build(5)从 Interface Builder 写入 UILabel 的 class file再打开SDK工具 Interface Builde
5、r在主视窗口或文件窗口;点击 Label选择: Tools - Connection Inspector移动鼠标在New Referencing Outlet 后面圆圈上; 圆圈变为(+); 拖向直线连接到Files Owner;放开鼠标选择键出现 countdownLabel; 选上它。选择: File - Save then close Interface Builde以上几步,已成功完成界面了,下面我们继续把程式添加我们的代码文件。(6) 在xCode打开 MinutesToMidnightAppDelegate.h 文件没修改前#import class MinutesToMidnig
6、htViewController;interface MinutesToMidnightAppDelegate : NSObject UIWindow *window; MinutesToMidnightViewController *viewController;property (nonatomic, retain) IBOutlet UIWindow *window;property (nonatomic, retain) IBOutlet MinutesToMidnightViewController *viewController;end没修改前修改后#import class Mi
7、nutesToMidnightViewController;interface MinutesToMidnightAppDelegate : NSObject IBOutlet UIWindow *window; IBOutlet MinutesToMidnightController *viewController; NSTimer *timer;-(void)onTimer;property (nonatomic, retain) IBOutlet UIWindow *window;property (nonatomic, retain) IBOutlet MinutesToMidnigh
8、tViewController *viewController;end(7) 在xCode打开 MinutesToMidnightAppDelegate.m 文件没修改前#import MinutesToMidnightAppDelegate.h#import MinutesToMidnightViewController.himplementation MinutesToMidnightAppDelegatesynthesize window;synthesize viewController;- (void)applicationDidFinishLaunching:(UIApplicat
9、ion *)application / Override point for customization after app launch window addSubview:viewController.view; window makeKeyAndVisible;- (void)dealloc viewController release; window release; super dealloc;end没修改前修改后#import MinutesToMidnightAppDelegate.h#import MinutesToMidnightViewController.himpleme
10、ntation MinutesToMidnightAppDelegatesynthesize window;synthesize viewController;- (void)applicationDidFinishLaunching:(UIApplication *)application timer = NSTimer scheduledTimerWithTimeInterval:(1.0) target:self selector:selector(onTimer) userInfo:nil repeats:YES; 不换行 / Override point for customizat
11、ion after app launch window addSubview:viewController.view; window makeKeyAndVisible;- (void)onTimer viewController updateLabel;- (void)applicationWillTerminate:(UIApplication *)application timer invalidate;- (void)dealloc timer release; viewController release; window release; super dealloc;end修改后(8
12、) 在xCode打开 MinutesToMidnightViewController.m 文件修改前#import MinutesToMidnightViewController.himplementation MinutesToMidnightViewController- (void)didReceiveMemoryWarning super didReceiveMemoryWarning;- (void)dealloc super dealloc;end修改前修改后#import MinutesToMidnightViewController.himplementation Minute
13、sToMidnightViewController- (void)viewDidLoad countdownLabel setFont:UIFont fontWithName:DBLCDTempBlack size:128.0; countdownLabel.text = I0A0IN6; super viewDidLoad;- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation return (interfaceOrientation = UIInterfaceOr
14、ientationPortrait);- (void)didReceiveMemoryWarning super didReceiveMemoryWarning; / Releases the view if it doesnt have a superview / Release anything thats not essential, such as cached data- (void)dealloc super dealloc;-(void)updateLabel NSDate* now = NSDate date; int hour = 23 - now dateWithCalen
15、darFormat:nil timeZone:nil hourOfDay; int min = 59 - now dateWithCalendarFormat:nil timeZone:nil minuteOfHour; int sec = 59 - now dateWithCalendarFormat:nil timeZone:nil secondOfMinute; countdownLabel.text = NSString stringWithFormat:%02d:%02d:%02d, hour, min,sec;end修改后最后在 xCode 选择 Build-Build and G
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 实例iPhone SDK 编程入门教程 实例 iPhone 编程 入门教程
限制150内