+ (UIButton *)buttonWithTitle:(NSString *)title target:(id)target selector:(SEL)selector
frame:(CGRect)frame image:(UIImage *)image imagePressed:(UIImage *)imagePressed darkTextColor:(BOOL)darkTextColor
{
UIButton *button = [[UIButton alloc] initWithFrame:frame];
button.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
[button setTitle:title forState:UIControlStateNormal];
if (darkTextColor)
{
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
}
else
{
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
}
UIImage *newImage = [image stretchableImageWithLeftCapWidth:12.0 topCapHeight:0.0];
[button setBackgroundImage:newImage forState:UIControlStateNormal];
UIImage *newPressedImage = [imagePressed stretchableImageWithLeftCapWidth:12.0 topCapHeight:0.0];
[button setBackgroundImage:newPressedImage forState:UIControlStateHighlighted];
[button addTarget:target action:selector forControlEvents:UIControlEventTouchUpInside];
// in case the parent view draws with a custom color or gradient, use a transparent color
button.backgroundColor = [UIColor clearColor];
return button;
}
UIButton 自定义
最新推荐文章于 2018-02-05 01:32:42 发布