码迷,mamicode.com
首页 > 移动开发 > 详细

完全靠代码生成的ios版hello,world

时间:2014-08-29 01:14:36      阅读:352      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   os   io   ar   2014   div   代码   

xcode5 运行在iphone retain 3.5" 模式下(即对应iphone4, iphone4s)需要开启ARC

//
//  main.m
//  Hello
//
//  Created by lishujun on 14-8-28.
//  Copyright (c) 2014年 lishujun. All rights reserved.
//

#import <UIKit/UIKit.h>


// 视图控制器对象
@interface HelloWorldViewController : UIViewController
@end

@implementation HelloWorldViewController

-(void) loadView
{
    //创建视图对象
    UIView *contentView = [[UIView alloc]initWithFrame:[[UIScreen mainScreen] applicationFrame]];
    contentView.backgroundColor = [UIColor lightGrayColor];
    self.view = contentView;
    
    //创建label对象
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0.0, 0.0, 320.0, 30.0)];
    label.text = @"Hello World";
    label.center = contentView.center;             // 垂直居中
    label.textAlignment = UITextAlignmentCenter;   // 水平居中
    label.backgroundColor = [UIColor clearColor];
    label.textColor = [UIColor redColor];
    
    //在视图上添加label
    [contentView addSubview:label];
}

@end


// 委托对象
@interface HelloWorldAppDelegate : NSObject <UIApplicationDelegate>
{
    IBOutlet UIWindow *window;
}

@property (nonatomic, retain) UIWindow *window;
//必须声明为属性,声明为局部变量则无法绘制视图,显示为黑屏
@end

@implementation HelloWorldAppDelegate
@synthesize window;

-(void) applicationDidFinishLaunching:(UIApplication *)application
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen]bounds]];
    HelloWorldViewController *viewController = [[HelloWorldViewController alloc]init];
    self.window.rootViewController = viewController;
    [self.window makeKeyAndVisible];
}

@end

// 程序入口
int main(int argc, char * argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, @"HelloWorldAppDelegate");
    }
}

 

完全靠代码生成的ios版hello,world

标签:style   blog   color   os   io   ar   2014   div   代码   

原文地址:http://www.cnblogs.com/code-style/p/3943902.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!