iOS代码Button Demo

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];   

UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(100, 200, 100, 50);
    btn.backgroundColor = [UIColor redColor];
    [btn addTarget:self action:@selector(onBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];

}

- (void)onBtnClick:(id)sender{

//你的功能代码

}

原文地址:https://www.cnblogs.com/i0ject/p/3955320.html