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