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

IOS-TargetAction

时间:2016-05-22 20:01:50      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:

创建一个UIButton 并用Target - Action来监听它的点击事件

Target -- self控制器 

Action -- 具体动作,self控制器中的某个方法

forControlEvents:UIControlEventTouchUpInside -- 表示监听的事件

 1 - (void)btnclick:(id)sender
 2 {
 3     NSLog(@"点击%@" , [sender class]);
 4 }
 5 
 6 - (void)viewDidLoad {
 7     [super viewDidLoad];
 8     // Do any additional setup after loading the view, typically from a nib.
 9     
10     UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
11     btn.frame = CGRectMake(100, 100, 100, 100);
12     [btn setTitle:@"点击" forState:UIControlStateNormal];
13     
14     [btn addTarget:self action:@selector(btnclick:) forControlEvents:UIControlEventTouchUpInside];
15     
16     [self.view addSubview:btn];
17 }

 

IOS-TargetAction

标签:

原文地址:http://www.cnblogs.com/vhuichen/p/5517315.html

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