-
- - (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;
- }
原文地址http://blog.csdn.net/duxinfeng2010/article/details/8687203