苹果开发 笔记(2)

        今晚看了一些网上的教程进行了一下练习,一个简单的按钮,从创建到监听行为。在as3里面只是需要几行代码就可以,在object-c里面创建一个按钮有时候也不知道在哪添加,甚至第一次连写代码的地方也不知道。动态写一个按钮和as3 有很相似的动作。添加按钮,监听事件。这两个过程还是相似的。

    学习oc的时候,我对此产生一个遗憾,创建一个实例的时候,java c# as3都是从new 开始,在oc 创建一个实例会有多种的方式。这个方式在学习的时候有一点疑惑和让人想不明白的地方。在赋值参数的,语法多少有点不适应的感觉。

 

    下面粘贴一下代码,记录一下今晚学的东西。

#import "ViewController.h"

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
   
    UIButton *btn2=[UIButton buttonWithType:UIButtonTypeRoundedRect ];
    btn2.frame=CGRectMake(10, 23, 200, 40);
    
    [btn2 setTitle:@"Test" forState:UIControlStateNormal];
    [btn2 addTarget:self action:@selector(testButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn2];
     
}
     
 -(void) testButtonClick
{
    
    UIAlertView *alert2=[[UIAlertView alloc] initWithTitle:@"Hello world"
                                                  message:@"ipad i love you"
                                                 delegate:self
                                        cancelButtonTitle:@"cancel" otherButtonTitles:nil];
    [alert2 show];
}
     

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(IBAction) btnClicked:(id) sender
{
    
  
    UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Hello world"
                                            message:@"ipad i love you"
                                            delegate:self
                                        cancelButtonTitle:@"cancel" otherButtonTitles:nil];
    
    [alert show];
    
}

@end


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值