Button 代码片

简介:

对Button进行一次封装

- (UIButton *)buttonWithFrame:(CGRect)frame  withNormalTitle:(NSString *)title  withOtherStateTitle:(NSString *)otherTitle action:(SEL)action  {     UIImage *buttonBackgroundImage = [[UIImage imageNamed:@"button_background.png"] stretchableImageWithLeftCapWidth:5 topCapHeight:5];     UIImage *disabledButtonBackgroundImage = [[UIImage imageNamed:@"button_background_disabled.png"] stretchableImageWithLeftCapWidth:5 topCapHeight:5];          UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];     button.frame = frame;     [button setTitle:title forState:UIControlStateNormal];     [button setTitle:otherTitle forState:UIControlStateDisabled];     [button setBackgroundImage:buttonBackgroundImage forState:UIControlStateNormal];     [button setBackgroundImage:disabledButtonBackgroundImage forState:UIControlStateDisabled];     [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];     [button setTitleColor:[UIColor grayColor] forState:UIControlStateDisabled];     [button addTarget:self action:action forControlEvents:UIControlEventTouchUpInside];     [self.view addSubview:button];          return button; } 


调用:

testButton = [self buttonWithFrame:CGRectMake(100,100,200,100) withNormalTitle:@"测试" withOtherStateTitle:@"测试" action:@selector(TestAction)];

测试效果:

  


     本文转自新风作浪 51CTO博客,原文链接:http://blog.51cto.com/duxinfeng/1208677,如需转载请自行联系原作者




相关文章
|
小程序
button按钮组件
button按钮组件
element-ui框架的el-dialog弹出框被遮罩层挡住了
element-ui框架的el-dialog弹出框被遮罩层挡住了
338 0
element-ui框架的el-dialog弹出框被遮罩层挡住了
el-dialog弹出框被遮罩层覆盖的解决办法
el-dialog弹出框被遮罩层覆盖的解决办法
1055 0
el-dialog弹出框被遮罩层覆盖的解决办法
el-dialog嵌套问题,第二个弹窗会被遮住的解决办法
el-dialog嵌套问题,第二个弹窗会被遮住的解决办法
1433 0
|
小程序 JavaScript
小程序点击事件,添加class样式
小程序点击事件,添加class样式
610 0
小程序点击事件,添加class样式
|
JavaScript 前端开发
Jquery 实现click 选中checkbox 多选(或一键选中全部或取消全部)实例代码
Jquery 实现click 选中checkbox 多选(或一键选中全部或取消全部)实例代码
279 0