forked from hboon/GlassButtons
-
Notifications
You must be signed in to change notification settings - Fork 1
/
MOGlassButton.m
142 lines (108 loc) · 4.49 KB
/
MOGlassButton.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
//
// MOGlassButton.m
// SimplyTweet
//
// Created by Hwee-Boon Yar on Jan/31/2010.
// Copyright 2010 MotionObj. All rights reserved.
//
#import "MOGlassButton.h"
#import "Global.h"
@implementation MOGlassButton
@synthesize gradientLayer1;
@synthesize gradientLayer2;
@synthesize outlineLayer;
- (void)setupLayers {
self.layer.cornerRadius = 8.0f;
self.layer.masksToBounds = YES;
self.layer.borderColor = [MO_RGBCOLOR(100, 103, 107) CGColor];
self.layer.borderWidth = 1.0f;
self.gradientLayer1 = [[[CAGradientLayer alloc] init] autorelease];
gradientLayer1.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height/2);
gradientLayer1.colors = [NSArray arrayWithObjects:(id)[MO_RGBACOLOR(255, 255, 255, 0.45) CGColor], (id)[MO_RGBACOLOR(255, 235, 255, 0.1) CGColor], nil];
[self.layer insertSublayer:gradientLayer1 atIndex:0];
self.gradientLayer2 = [[[CAGradientLayer alloc] init] autorelease];
gradientLayer2.frame = CGRectMake(0, self.frame.size.height/2, self.frame.size.width, self.frame.size.height/2);
gradientLayer2.colors = [NSArray arrayWithObjects:(id)[MO_RGBACOLOR(205, 205, 205, 0) CGColor], (id)[MO_RGBACOLOR(235, 215, 215, 0.2) CGColor], nil];
self.outlineLayer = [[[CALayer alloc] init] autorelease];
outlineLayer.frame = CGRectMake(0, 1, self.frame.size.width, self.frame.size.height);
outlineLayer.borderColor = [MO_RGBCOLOR(255, 255, 255) CGColor];
outlineLayer.borderWidth = 1.0f;
outlineLayer.borderWidth = 1.0f;
outlineLayer.opacity = 0.2;
}
- (id)initWithFrame:(CGRect)aRect {
if ((self = [super initWithFrame:aRect])) {
[self setupLayers];
}
return self;
}
- (void)awakeFromNib {
[super awakeFromNib];
[self setupLayers];
}
- (void)dealloc {
self.gradientLayer1 = nil;
self.gradientLayer2 = nil;
self.outlineLayer = nil;
[super dealloc];
}
- (void)layoutSubviews {
[super layoutSubviews];
gradientLayer1.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height/2);
gradientLayer2.frame = CGRectMake(0, self.frame.size.height/2, self.frame.size.width, self.frame.size.height/2);
outlineLayer.frame = CGRectMake(0, 1, self.frame.size.width, self.frame.size.height);
}
#pragma mark Default Button Background Colors
- (void)setupForStandardButtons {
[self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[self setTitleColor:MO_RGBCOLOR(205, 212, 220) forState:UIControlStateDisabled];
self.titleLabel.shadowOffset = CGSizeMake(0, -1);
//self.titleLabel.shadowColor = MO_RGBCOLOR(192, 73, 84);
self.titleLabel.shadowColor = MO_RGBACOLOR(0, 0, 0, 0.5);
self.titleLabel.font = [UIFont boldSystemFontOfSize:20];
}
- (void)setupAsGreenButton {
[self setBackgroundColor:MO_RGBCOLOR(24, 157, 22) forState:UIControlStateNormal];
[self setBackgroundColor:MO_RGBCOLOR(9, 54, 14) forState:UIControlStateHighlighted];
[self setBackgroundColor:MO_RGBACOLOR(24, 157, 22, 0.5) forState:UIControlStateDisabled];
[self setupForStandardButtons];
}
- (void)setupAsRedButton {
[self setBackgroundColor:MO_RGBCOLOR(160, 1, 20) forState:UIControlStateNormal];
[self setBackgroundColor:MO_RGBCOLOR(120, 0, 0) forState:UIControlStateHighlighted];
[self setBackgroundColor:MO_RGBACOLOR(160, 1, 20, 0.5) forState:UIControlStateDisabled];
[self setupForStandardButtons];
}
- (void)setupAsLightGrayButton {
[self setBackgroundColor:MO_RGBCOLOR(200, 200, 200) forState:UIControlStateNormal];
[self setBackgroundColor:MO_RGBCOLOR(160, 160, 160) forState:UIControlStateHighlighted];
[self setBackgroundColor:MO_RGBACOLOR(200, 200, 200, 0.5) forState:UIControlStateDisabled];
[self setupForStandardButtons];
}
- (void)setupAsDarkGrayButton {
[self setBackgroundColor:MO_RGBCOLOR(75, 75, 75) forState:UIControlStateNormal];
[self setBackgroundColor:MO_RGBCOLOR(115, 115, 115) forState:UIControlStateHighlighted];
[self setBackgroundColor:MO_RGBACOLOR(75, 75, 75, 0.5) forState:UIControlStateDisabled];
[self setupForStandardButtons];
}
- (void)setupAsSmallGreenButton {
[self setupAsGreenButton];
self.titleLabel.font = [UIFont boldSystemFontOfSize:15];
self.layer.cornerRadius = 4.0f;
}
- (void)setupAsSmallRedButton {
[self setupAsRedButton];
self.titleLabel.font = [UIFont boldSystemFontOfSize:15];
self.layer.cornerRadius = 4.0f;
}
- (void)setupAsSmallLightGrayButton {
[self setupAsLightGrayButton];
self.titleLabel.font = [UIFont boldSystemFontOfSize:15];
self.layer.cornerRadius = 4.0f;
}
- (void)setupAsSmallDarkGrayButton {
[self setupAsDarkGrayButton];
self.titleLabel.font = [UIFont boldSystemFontOfSize:15];
self.layer.cornerRadius = 4.0f;
}
@end