object c 源代码动态增加按钮,并给按钮一个点击事件

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 , , , . Bookmark the permalink.
月小升QQ 2651044202, 技术交流QQ群 178491360
首发地址:月小升博客https://java-er.com/blog/oc-add-button/
无特殊说明,文章均为月小升原创,欢迎转载,转载请注明本文地址,谢谢
您的评论是我写作的动力

Leave a Reply

Your email address will not be published. Required fields are marked *

*

*

  

  

About Me

静水流深,水滴石穿