抽取一个简单的按钮方法

 1 //抽出一个按钮
 2 - (UIButton *)buttonWithTitle:(NSString *)title action:(SEL)action{
 3     UIButton *button = [[UIButton alloc] init];
 4     [button setTitle:title forState:UIControlStateNormal];
 5     [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
 6     [button setTitleColor:[UIColor blueColor] forState:UIControlStateHighlighted];
 7     button.backgroundColor = [UIColor purpleColor];
 8     [button sizeToFit];
 9     [self.view addSubview:button];
10    
11     [button addTarget:self action:action forControlEvents:UIControlEventTouchUpInside];
12     return button;
13 }
原文地址:https://www.cnblogs.com/zhufengshibei/p/5099625.html