iphone成长之路-第一个Hello World项目

先创建一个空白的iphone项目:

选图中已经选中的图标,然后点击next,进入下一步:

为这个项目命名,然后next

选择想要储存的位置,然后创建就ok了

然后创建类来定义界面:

选择图中选中的类进行创建,点击下一步

为类命名,进行下一步

选取路径进行创建

创建好的项目为

在DemoViewController类中定义界面:(类中大多代码为自动生成,在此只写重要代码)

[cpp]  view plain copy
  1. /*DemoViewController.h*/  
  2. #import <UIKit/UIKit.h>  
  3.   
  4. @interface DemoViewController : UIViewController  
  5. {  
  6.     //定义一个Label,用来当容器  
  7.     UILabel * helloLabel;  
  8. }  
  9.   
  10. //nonatomic:提高效率,retain:setter方法对参数release旧值,返回新值  
  11. @property(nonatomic,retain)UILabel* helloLabel;  
  12.   
  13. @end  

[cpp]  view plain copy
  1. /*DemoViewController.m*/  
  2. #import "DemoViewController.h"  
  3.   
  4. @implementation DemoViewController  
  5. @synthesize helloLabel;//预编译  
  6.   
  7. // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.  
  8. - (void)viewDidLoad  
  9. {  
  10.     //CGRectMake(CGFloat x, CGFloat y, CGFloat width, CGFloat height)设置Label显示的位置  
  11.     //CGRectMake(和左边边框的距离,和上边边框的距离,Label的长度,Label的高度)  
  12.     helloLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 50, 300, 60)];  
  13.       
  14.     //设置Label中要显示的内容  
  15.     helloLabel.text = @"Hello World";  
  16.     //对齐方式   局中(一行的中间)  
  17.     helloLabel.textAlignment = UITextAlignmentCenter;  
  18.     //设置字体颜色为红色  
  19.     helloLabel.textColor = [UIColor redColor];  
  20.     //设置字体字号为20  
  21.     helloLabel.font = [UIFont systemFontOfSize:20];  
  22.     //把Label添加到View中  
  23.     [self.view addSubview:helloLabel];  
  24.     [super viewDidLoad];  
  25. }  


[cpp]  view plain copy
  1. /*AppDelegate.h*/  
  2. #import <UIKit/UIKit.h>  
  3. @class DemoViewController;  
  4. @interface AppDelegate : UIResponder <UIApplicationDelegate>  
  5. {  
  6.     //创建DemoViewController类的对象  
  7.     DemoViewController* _iDemoViewController;  
  8. }  
  9. @property (nonatomic,retain)DemoViewController* iDemoViewController;  
  10. @property (strong, nonatomic)UIWindow *window;  
  11.   
  12. @end  

[cpp]  view plain copy
  1. /*AppDelegate.m*/  
  2. #import "AppDelegate.h"  
  3. #import "DemoViewController.h"  
  4. @implementation AppDelegate  
  5.   
  6. //备份变量名   通俗理解:作用就是让编写者学会运用self  
  7. @synthesize window = _window;  
  8. @synthesize iDemoViewController = _iDemoViewController;  
  9.   
  10. - (void)dealloc  
  11. {  
  12.       
  13.     self.iDemoViewController = nil;  
  14.     [_window release];  
  15.     [super dealloc];  
  16. }  
  17.   
  18. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions  
  19. {  
  20.     self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];  
  21.     // Override point for customization after application launch.  
  22.     self.window.backgroundColor = [UIColor whiteColor];  
  23.       
  24.       
  25.     //创建出一个临时的Demo  
  26.     DemoViewController *demo = [[DemoViewController alloc]init];  
  27.       
  28.     self.iDemoViewController = demo;  
  29.     [demo release];//释放临时Demo  
  30.     //添加到window中  
  31.     [self.window addSubview:self.iDemoViewController.view];  
  32.       
  33.       
  34.     [self.window makeKeyAndVisible];  
  35.     return YES;  
  36. }  


然后运行项目就可以得到我们特别熟悉而又陌生的HelloWorld了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值