iOS开发 Button自定义

 - (void)viewDidLoad {

    [super viewDidLoad];   

    //自定义button控件

    UIButton *button=[UIButton buttonWithType:UIButtonTypeRoundedRect];

    //设置button的位置和大小

    [button setFrame:CGRectMake(50, 100, 50, 100)];

    //设置button的文字

    [button setTitle:@"确定" forState:UIControlStateNormal];

    //设置背景的颜色

    button.backgroundColor=[UIColor blueColor];

    //绑定动作

    [button addTarget:self action:@selector(clickConfirm) forControlEvents:UIControlEventTouchUpInside];

    // 添加到视图中

    [self.view addSubview:button];

-(void) clickConfirm{

self.lblTitle.text=@"test";

}

原文地址:https://www.cnblogs.com/laugher/p/4781984.html