-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMKButton.m
More file actions
119 lines (99 loc) · 3.24 KB
/
MKButton.m
File metadata and controls
119 lines (99 loc) · 3.24 KB
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
//
// MKButton.m
// MetroKit
//
// Created by Shawn Wall on 7/19/12.
// Copyright (c) 2012 TwoTap Labs. All rights reserved.
//
#import "MKButton.h"
#import <QuartzCore/QuartzCore.h>
#define kMetroButtonSelectedAlpha 0.5
#define kMetroButtonDisabledAlpha 0.8
@interface MKButton ()
@property (strong, nonatomic) UIColor *borderColor;
@end
@implementation MKButton
@synthesize borderColor = _borderColor;
- (id)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self) {
[self setDefaults];
}
return self;
}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self setDefaults];
}
return self;
}
- (void)setDefaults {
[self setBackgroundColor:[UIColor blackColor]];
[self setBorderColor:[UIColor whiteColor]];
[self.titleLabel setFont:[UIFont systemFontOfSize:16.0]];
[self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//[self setTitleColor:[self.borderColor colorWithAlphaComponent:kMetroButtonSelectedAlpha] forState:UIControlStateSelected];
//[self setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted];
//[self setTitleColor:[self.borderColor colorWithAlphaComponent:kMetroButtonDisabledAlpha] forState:UIControlStateDisabled];
[self setBackgroundColor:[UIColor blackColor] forState:UIControlStateNormal];
[self setBackgroundColor:[UIColor grayColor] forState:UIControlStateSelected];
[self setBackgroundColor:[UIColor grayColor] forState:UIControlStateHighlighted];
[self setBackgroundColor:[UIColor blackColor] forState:UIControlStateDisabled];
[self.layer setBorderWidth:1.0];
[self.layer setMasksToBounds:YES];
}
- (void)setHighlighted:(BOOL)highlighted
{
[super setHighlighted:highlighted];
if (highlighted)
{
self.backgroundColor = [UIColor grayColor];
}
else
{
self.backgroundColor = [UIColor blackColor];
}
}
//- (void)setEnabled:(BOOL)enabled {
// [super setEnabled:enabled];
// [self setNeedsDisplay];
//}
- (void)setTintColor:(UIColor *)tintColor {
//todo support tinting
[super setTintColor:tintColor];
}
- (void)setBorderColor:(UIColor *)borderColor {
_borderColor = borderColor;
[self.layer setBorderColor:[self.borderColor CGColor]];
}
- (void)setSelected:(BOOL)selected {
[super setSelected:selected];
if (self.selected) {
[self.layer setBorderColor:[[self.borderColor colorWithAlphaComponent:kMetroButtonSelectedAlpha] CGColor]];
}
else {
[self.layer setBorderColor:[self.borderColor CGColor]];
}
[self setNeedsDisplay];
}
- (void)drawRect:(CGRect)rect
{
[super drawRect:rect];
if (self.enabled) {
if (self.selected) {
[self.layer setBorderColor:[[self.borderColor colorWithAlphaComponent:kMetroButtonSelectedAlpha] CGColor]];
}
else {
[self.layer setBorderColor:[self.borderColor CGColor]];
}
}
else {
[self.layer setBorderColor:[[self.borderColor colorWithAlphaComponent:kMetroButtonDisabledAlpha] CGColor]];
}
}
- (void)setBackgroundColor:(UIColor *)backgroundColor forState:(UIControlState)state
{
}
@end