I need to set a rounded rect as background for UIButton, and I need to generate it programmatically, related on color
+ (UIImage *)buttonBackgroundWithColor:(UIColor *)color {
UIGraphicsBeginImageContextWithOptions(CGSizeMake(30.f, 30.f), NO, 1.0f);
CGContextRef context = UIGraphicsGetCurrentContext();
[color setStroke];
UIBezierPath *bezierPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(2.f, 2.f, 26.f, 26.f)
cornerRadius:7.f];
CGContextSetStrokeColorWithColor(context, color.CGColor);
bezierPath.lineWidth = 1.f;
[bezierPath stroke];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return [[image copy] resizableImageWithCapInsets:UIEdgeInsetsMake(10.f, 10.f, 10.f, 10.f)];
}
I've tried to do it like it described here https://stackoverflow.com/a/19142851/1090590
but, my button background is 'blurred'
What am I doing wrong? How can I make it legible?