forked from 1061961387/Eliminate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EButton.m
55 lines (46 loc) · 1.71 KB
/
EButton.m
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//
// EButton.m
// Eliminate
//
// Created by 裕福 on 15/5/14.
// Copyright (c) 2015年 裕福. All rights reserved.
//
#import "EButton.h"
@implementation EButton
- (void)setType:(EBUTTONCOLOR)type
{
if (type == EBUTTONCOLOR_RED) {
[self setBackgroundImage:[self imageWithColor:[UIColor redColor]] forState:UIControlStateNormal];
_type = EBUTTONCOLOR_RED;
}else if (type == EBUTTONCOLOR_YELLOW) {
[self setBackgroundImage:[self imageWithColor:[UIColor yellowColor]] forState:UIControlStateNormal];
_type = EBUTTONCOLOR_YELLOW;
}else if (type == EBUTTONCOLOR_BLUE) {
[self setBackgroundImage:[self imageWithColor:[UIColor blueColor]] forState:UIControlStateNormal];
_type = EBUTTONCOLOR_BLUE;
}else if (type == EBUTTONCOLOR_GREEN) {
[self setBackgroundImage:[self imageWithColor:[UIColor greenColor]] forState:UIControlStateNormal];
_type = EBUTTONCOLOR_GREEN;
}else{
[self setBackgroundImage:[self imageWithColor:[UIColor purpleColor]] forState:UIControlStateNormal];
_type = EBUTTONCOLOR_PURPLE;
}
}
-(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;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/
@end