Here's what I've got:
#import <QuartzCore/QuartzCore.h>
+ (void)setCornerRadius:(CGFloat)radius ofView:(UIView*)view
{
view.layer.cornerRadius = radius;
view.layer.masksToBounds = YES;
}
+ (void)setBorderWidth:(CGFloat)width ofView:(UIView*)view
{
view.layer.borderWidth = width;
}
+ (void)setBorderColor:(UIColor*)color ofView:(UIView*)view
{
view.layer.borderColor = [color CGColor];
}
+ (void)styleButton:(UIButton*)button
{
[Common setBorderWidth:1 ofView:button];
[Common setCornerRadius:5 ofView:button];
[Common setBorderColor:[UIColor blueColor] ofView:button];
[button setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
UIGraphicsBeginImageContextWithOptions(button.frame.size, YES, 0);
CGContextRef context = UIGraphicsGetCurrentContext();
[[UIColor blueColor] setFill];
CGContextFillRect(context, CGRectMake(0, 0, button.frame.size.width, button.frame.size.height));
UIImage* image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[button setBackgroundImage:image forState:UIControlStateHighlighted];
}
Note that this will only work for UIButtonTypeCustom
buttons.
Of course, if you use another tintColor
in your app, replace [UIColor blueColor]
.