抽取一个简单的按钮方法

 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 }

 

posted @ 2016-01-04 17:15  竹峰拾贝  阅读(188)  评论(0编辑  收藏  举报