我正在使用1px xpp图像通过此类别方法更改UIButton的背景颜色:
- (void)setBackgroundColor:(UIColor *)backgroundColor forState:(UIControlState)state { UIGraphicsBeginImageContextWithOptions(CGSizeMake(1,1),NO,0); [backgroundColor setFill]; CGContextFillRect(UIGraphicsGetCurrentContext(),CGRectMake(0,1,1)); UIImage *backgroundImage = UIGraphicsGetImageFromCurrentImageContext(); [self setBackgroundImage:backgroundImage forState:state]; UIGraphicsEndImageContext(); }
但是,这会覆盖我的.layer.cornerRadius设置.我需要一个带圆角的按钮,但也需要一个可以突出显示的背景颜色.
有什么方法吗?角半径需要是动态的.
@H_502_8@