实例_iPhone_SDK_编程入门教程

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

实例iPhoneSDK编程入门教程DAYONE-MinutesToMidnight大家一起来建立我们的第一个iPhoneapp,给你的iPhone计算离午夜12:00点的剩余时间。首先运行以安装好的xCode选择:File-NewProject.从NewProject窗口选择:iPhoneOS-Applications-View-BasedApplication命名:我这里命名为MinutesToMidnight(1)UIView界面设置-黑色背景,红色字体,让它看起来像一个闹钟。双击文件:MinutesToMidnightViewController.xib;然后InterfaceBuilder会自动打开,在这里我们可以编辑改变界面选择:Tools-RevealInDocumentWindow-View选择:Tools-AttributesInspector在色条内选择黑色,可以看到背景变为黑色(2)加入UILabel显示我们的倒数时间选择:Tools-Library;从Library显示菜单中拖拉一个Label到MainView在主显示上点击Label;从LabelAttributes上选着字体的颜色和字体大小。(3)把界面文件更新到我们的代码文件上面在MinutesToMidnightViewController.xib文件窗口,选择:File'sOwner(这步很关键,我在第一次编辑时没成功就因为忘了这一步)选择:Tools-IdenityInspector在Idenityinspector中间ClassOutlets按+;把myOutlet1改为countdownLabel;把id改为UILabel;按回车,确定已更改。(4)写入MinutesToMidnightViewController.h和MinutesToMidnightViewController.m确认还在MinutesToMidnightViewController.xib文件窗口,选择:File'sOwner选择:File-WriteClassFiles在SaveAs:MinutesToMidnightViewController点击:Save点击:Merge在右下角Actions按下选(bottomright)SelectLeft点击:上方红色小圈关闭窗口点击:Save关闭所有merge窗口打开xCode;选择Build-Build(5)从InterfaceBuilder写入UILabel的classfile再打开SDK工具InterfaceBuilder在主视窗口或文件窗口;点击Label选择:Tools-ConnectionInspector移动鼠标在NewReferencingOutlet后面圆圈上;圆圈变为(+);拖向直线连接到File'sOwner;放开鼠标选择键出现countdownLabel;选上它。选择:File-SavethencloseInterfaceBuilde以上几步,已成功完成界面了,下面我们继续把程式添加我们的代码文件。(6)在xCode打开MinutesToMidnightAppDelegate.h文件//没修改前//#importUIKit/UIKit.h@classMinutesToMidnightViewController;@interfaceMinutesToMidnightAppDelegate:NSObjectUIApplicationDelegate{UIWindow*window;MinutesToMidnightViewController*viewController;}@property(nonatomic,retain)IBOutletUIWindow*window;@property(nonatomic,retain)IBOutletMinutesToMidnightViewController*viewController;@end//没修改前////修改后//#importUIKit/UIKit.h@classMinutesToMidnightViewController;@interfaceMinutesToMidnightAppDelegate:NSObjectUIApplicationDelegate{IBOutletUIWindow*window;IBOutletMinutesToMidnightController*viewController;NSTimer*timer;}-(void)onTimer;@property(nonatomic,retain)IBOutletUIWindow*window;@property(nonatomic,retain)IBOutletMinutesToMidnightViewController*viewController;@end(7)在xCode打开MinutesToMidnightAppDelegate.m文件//没修改前//#importMinutesToMidnightAppDelegate.h#importMinutesToMidnightViewController.h@implementationMinutesToMidnightAppDelegate@synthesizewindow;@synthesizeviewController;-(void)applicationDidFinishLaunching:(UIApplication*)application{//Overridepointforcustomizationafterapplaunch[windowaddSubview:viewController.view];[windowmakeKeyAndVisible];}-(void)dealloc{[viewControllerrelease];[windowrelease];[superdealloc];}@end//没修改前////修改后//#importMinutesToMidnightAppDelegate.h#importMinutesToMidnightViewController.h@implementationMinutesToMidnightAppDelegate@synthesizewindow;@synthesizeviewController;-(void)applicationDidFinishLaunching:(UIApplication*)application{timer=[NSTimerscheduledTimerWithTimeInterval:(1.0)target:selfselector:@selector(onTimer)userInfo:nilrepeats:YES];//不换行//Overridepointforcustomizationafterapplaunch[windowaddSubview:viewController.view];[windowmakeKeyAndVisible];}-(void)onTimer{[viewControllerupdateLabel];}-(void)applicationWillTerminate:(UIApplication*)application{[timerinvalidate];}-(void)dealloc{[timerrelease];[viewControllerrelease];[windowrelease];[superdealloc];}@end//修改后//(8)在xCode打开MinutesToMidnightViewController.m文件//修改前//#importMinutesToMidnightViewController.h@implementationMinutesToMidnightViewController-(void)didReceiveMemoryWarning{[superdidReceiveMemoryWarning];}-(void)dealloc{[superdealloc];}@end//修改前////修改后//#importMinutesToMidnightViewController.h@implementationMinutesToMidnightViewController-(void)viewDidLoad{[countdownLabelsetFont:[UIFontfontWithName:@DBLCDTempBlacksize:128.0]];countdownLabel.text=@I0A0IN6;[superviewDidLoad];}-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{return(interfaceOrientation==UIInterfaceOrientationPortrait);}-(void)didReceiveMemoryWarning{[superdidReceiveMemoryWarning];//Releasestheviewifitdoesn'thaveasuperview//Releaseanythingthat'snotessential,suchascacheddata}-(void)dealloc{[superdealloc];}-(void)updateLabel{NSDate*now=[NSDatedate];inthour=23-[[nowdateWithCalendarFormat:niltimeZone:nil]hourOfDay];intmin=59-[[nowdateWithCalendarFormat:niltimeZone:nil]minuteOfHour];intsec=59-[[nowdateWithCalendarFormat:niltimeZone:nil]secondOfMinute];countdownLabel.text=[NSStringstringWithFormat:@%02d:%02d:%02d,hour,min,sec];}@end//修改后//最后在xCode选择Build-BuildandGo下载今天程序文件:MinsToMidnight.zip实例iPhoneSDK编程入门教程,来源于,大家有空可以去看看原文;下面文章本人根据appsamuck这个网站加以翻译,修改及测试,希望大家多多交流。一切版权归所有。实例iPhoneSDK编程入门教程-第二天DayTwoBonfire今天试试运用UIImageView来制作一个营火动画首先运行以安装好的xCode,和第一天一样选择:File-NewProject.从NewProject窗口选择:iPhoneOS-Applications-View-BasedApplication命名:我这里命名为Bonfire(1)在xcode打开BonfireViewController.m文件在-(void)viewDidLoad{}里面添加代码,如下-(void)viewDidLoad{//createtheviewthatwillexecuteouranimationUIImageView*campFireView=[[UIImageViewalloc]initWithFrame:self.view.frame];//loadalltheframesofouranimationcampFireView

1 / 86
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功