-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUIButton+PLColor.m
More file actions
35 lines (26 loc) · 845 Bytes
/
UIButton+PLColor.m
File metadata and controls
35 lines (26 loc) · 845 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//
// UIButton+PLColor.m
// www.gulosolutions.com
//
// Created by Zachary Wilson on 3/17/15.
// Copyright (c) 2015 Gulo Solutions. All rights reserved.
//
#import "UIButton+PLColor.h"
@implementation UIButton (PLColor)
+ (UIImage *)imageWithColor:(UIColor *)color
{
CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
- (void)setBackgroundColor:(UIColor *)color forState:(UIControlState)state
{
UIImage *image = [UIButton imageWithColor:color];
[self setBackgroundImage:image forState:state];
}
@end