-
Notifications
You must be signed in to change notification settings - Fork 87
/
MOGlassButton.mm
109 lines (80 loc) · 3.8 KB
/
MOGlassButton.mm
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
//
// MOGlassButton.m
// SimplyTweet
//
// Created by Hwee-Boon Yar on Jan/31/2010.
// Copyright 2010 MotionObj. All rights reserved.
//
// Enhanced by Daniel Sachse on 10/30/10.
// Copyright 2010 coffeecoding. All rights reserved.
//
#import "MOGlassButton.h"
#import "ColorC.h"
@implementation MOGlassButton
@synthesize gradientLayer1;
@synthesize gradientLayer2;
@synthesize outlineLayer;
- (void)setupLayers {
self.layer.cornerRadius = 8.0f;
self.layer.masksToBounds = YES;
self.layer.borderColor = [[UIColor colorFromRGBIntegers:100 green:103 blue:107 alpha:1.0f] CGColor];
self.layer.borderWidth = 1.0f;
self.gradientLayer1 = [[CAGradientLayer alloc] init];
gradientLayer1.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height/2);
gradientLayer1.colors = @[(id)[[UIColor colorFromRGBIntegers:255 green:255 blue:255 alpha:0.45f] CGColor], (id)[[UIColor colorFromRGBIntegers:255 green:235 blue:255 alpha:0.1f] CGColor]];
[self.layer insertSublayer:gradientLayer1 atIndex:0];
self.gradientLayer2 = [[CAGradientLayer alloc] init];
gradientLayer2.frame = CGRectMake(0, self.frame.size.height/2, self.frame.size.width, self.frame.size.height/2);
gradientLayer2.colors = @[(id)[[UIColor colorFromRGBIntegers:205 green:205 blue:205 alpha:0.0f] CGColor], (id)[[UIColor colorFromRGBIntegers:235 green:215 blue:215 alpha:0.2f] CGColor]];
self.outlineLayer = [[CALayer alloc] init];
outlineLayer.frame = CGRectMake(0, 1, self.frame.size.width, self.frame.size.height);
outlineLayer.borderColor = [[UIColor colorFromRGBIntegers:255 green:255 blue:255 alpha:1.0f] CGColor];
outlineLayer.borderWidth = 1.0f;
outlineLayer.borderWidth = 1.0f;
outlineLayer.opacity = 0.2f;
}
- (id)initWithFrame:(CGRect)aRect {
if (self = [super initWithFrame:aRect]) {
[self setupLayers];
}
return self;
}
- (void)awakeFromNib {
[super awakeFromNib];
}
- (void)layoutSubviews {
[super layoutSubviews];
}
#pragma mark Default Button Background Colors
- (void)setupForStandardButtons {
[self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[self setTitleColor:[UIColor colorFromRGBIntegers:205 green:212 blue:220 alpha:1.0f] forState:UIControlStateDisabled];
self.titleLabel.font = [UIFont systemFontOfSize:20 weight:UIFontWeightLight];
}
- (void)setupAsGreenButton {
[self setBackgroundColor:[UIColor colorFromRGBIntegers:24 green:157 blue:22 alpha:1.0f] forState:UIControlStateNormal];
[self setBackgroundColor:[UIColor colorFromRGBIntegers:9 green:54 blue:14 alpha:1.0f] forState:UIControlStateHighlighted];
[self setBackgroundColor:[UIColor colorFromRGBIntegers:24 green:157 blue:22 alpha:1.0f] forState:UIControlStateDisabled];
[self setupForStandardButtons];
}
- (void)setupAsRedButton {
[self setBackgroundColor:[UIColor colorFromRGBIntegers:160 green:1 blue:20 alpha:1.0f] forState:UIControlStateNormal];
[self setBackgroundColor:[UIColor colorFromRGBIntegers:120 green:0 blue:0 alpha:1.0f] forState:UIControlStateHighlighted];
[self setBackgroundColor:[UIColor colorFromRGBIntegers:160 green:1 blue:20 alpha:1.0f] forState:UIControlStateDisabled];
[self setupForStandardButtons];
}
- (void)setupAsWhiteButton {
[self setBackgroundColor:[UIColor colorFromRGBIntegers:160 green:160 blue:160 alpha:1.0f] forState:UIControlStateNormal];
[self setBackgroundColor:[UIColor colorFromRGBIntegers:80 green:80 blue:80 alpha:1.0f] forState:UIControlStateHighlighted];
[self setBackgroundColor:[UIColor colorFromRGBIntegers:160 green:160 blue:160 alpha:1.0f] forState:UIControlStateDisabled];
[self setupForStandardButtons];
}
- (void)setupAsSmallGreenButton {
[self setupAsGreenButton];
self.titleLabel.font = [UIFont systemFontOfSize:15 weight:UIFontWeightLight];
}
- (void)setupAsSmallRedButton {
[self setupAsRedButton];
self.titleLabel.font = [UIFont systemFontOfSize:15 weight:UIFontWeightLight];
}
@end