Im changes the background color UIButtonusing this category method using a 1px image by 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();
}
However, this overrides my setting .layer.cornerRadius. I need a button with rounded corners, but also one whose background color I can change to the selected one.
How to get around this? The radius of the angle must be dynamic.
Luke source
share