UIButton控件

-(void)viewDidLoad{

//初始化

self.btn1 = [UIBotton buttonWithType:UIButtonTypeRoundedRect];

//设置大小

self.btn1.frame = CGRectMake(20,20,100,50);

//设置标题

[self.btn1 setTitle:@"Hello" forState:UIControlStateNormal];

//添加点击事件

[self.btn1 addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];

//呈现控件

[self.view addSubView:self.btn1];

}

//按钮的点击事件

-(IBAction) click:(id)sender

{

  UIButton * button = (UIButton*)sender;

  NSString *title = btn.titleLabel.text;

  NSLog(@"%@",title);

}

posted @ 2014-08-06 14:17  迷茫的程序小生  阅读(188)  评论(0编辑  收藏  举报