纯代码写iOS

纯代码写iOS
发表于2年前(2013-05-10 15:07)      阅读( 62) | 评论( 0)            0人收藏此文章,我要收藏
赞0

代码是这里的 http://blog.csdn.net/rorger/article/details/7276484

1.新建一个空视图项目

2.代理AppDelegate头文件声明ViewController

?
1
@property (strong, nonatomic) TestViewController *viewController;
3.代理AppDelegate源文件的didFinishLaunchingWithOptions方法添加代码
?
1
2
self.viewController = [[TestViewController alloc] init];
    self.window.rootViewController = self.viewController;
4.TestViewController 的viewDidLoad方法
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
UIView *contentView = [[UIView alloc]initWithFrame: [[UIScreen mainScreen] applicationFrame]];
    contentView.backgroundColor = [UIColor lightGrayColor];
    self.view = contentView;
//    [contentView release];
   
    //label
    UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(0.0, 0.0, 320, 30)];
    label.text = @ "PureCode" ;
    label.center = contentView.center;
    label.backgroundColor = [UIColor lightGrayColor];
    label.textAlignment = UITextAlignmentCenter;
    [self.view addSubview:label];
//    [label release];
   
    //button
    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [button setFrame:CGRectMake(10.0, 20.0, 77, 37)];
    [button setTitle:@ "Button" forState:UIControlStateNormal];
    [button setTitle:@ "ok" forState:UIControlStateDisabled];
    [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
5.添加button的点击事件
?
1
2
3
4
5
6
7
8
- ( void )buttonPressed:(id)sender{
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@ "ButtonPressed"
                                                   message:@ "You have pressed the button"
                                                  delegate:nil
                                         cancelButtonTitle:@ "Yesh"
                                         otherButtonTitles: nil];
    [alert show];
}
6.没了,就这么多
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值