发表于 2015-11-19 12:15:39 by 月小升
object c 源代码动态增加按钮,并给按钮一个点击事件
- (void)viewDidLoad {
[super viewDidLoad];
CGRect frame = CGRectMake(90, 200, 200, 60);
UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = frame;
btn.backgroundColor = [UIColor clearColor];
[btn setTitle:@"动态添加一个按钮!" forState:UIControlStateNormal];
[btn addTarget:self action:@selector(Edit:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
//一下代码为点击事件,注释的代码打开,可以出来一个消息弹窗
-(IBAction)Edit:(id)sender{
//NSString *msg = @"f*au*ck U";
//UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"message" message:msg delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil]; [alert show];
}
This entry was posted in
Xcode and tagged
mac,
object-c,
xcode,
按钮. Bookmark the
permalink.
月小升QQ 2651044202, 技术交流QQ群 178491360
首发地址:
月小升博客 –
https://java-er.com/blog/oc-add-button/
无特殊说明,文章均为月小升原创,欢迎转载,转载请注明本文地址,谢谢