Skip to content

Instantly share code, notes, and snippets.

@terut
Created November 30, 2012 08:30
Show Gist options
  • Save terut/4174526 to your computer and use it in GitHub Desktop.
Save terut/4174526 to your computer and use it in GitHub Desktop.
UIButton background for state
- (void)setBackgroundColor:(UIColor *)backgroundColor forState:(UIControlState)state
{
CGRect rect = CGRectMake(0, 0, 1, 1);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, backgroundColor.CGColor);
CGContextFillRect(context, rect);
UIImage *backgroundImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[self setBackgroundImage:backgroundImage forState:state];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment