forked from dogo/SCLAlertView
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSCLButton.m
More file actions
100 lines (87 loc) · 2.29 KB
/
SCLButton.m
File metadata and controls
100 lines (87 loc) · 2.29 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
//
// SCLButton.m
// SCLAlertView
//
// Created by Diogo Autilio on 9/26/14.
// Copyright (c) 2014 AnyKey Entertainment. All rights reserved.
//
#import "SCLButton.h"
@implementation SCLButton
- (id)init
{
self = [super init];
if (self) {
// Do something
}
return self;
}
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if(self) {
// Do something
}
return self;
}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Do something
}
return self;
}
- (void)setHighlighted:(BOOL)highlighted
{
if(highlighted)
{
self.backgroundColor = [self darkerColorForColor:_defaultBackgroundColor];
}
else
{
self.backgroundColor = _defaultBackgroundColor;
}
[super setHighlighted:highlighted];
}
- (void)setDefaultBackgroundColor:(UIColor *)defaultBackgroundColor
{
self.backgroundColor = _defaultBackgroundColor = defaultBackgroundColor;
}
#pragma mark - Button Apperance
- (void)parseConfig:(NSDictionary *)buttonConfig
{
if ([buttonConfig objectForKey:@"backgroundColor"])
{
self.defaultBackgroundColor = [buttonConfig objectForKey:@"backgroundColor"];
}
if ([buttonConfig objectForKey:@"borderColor"])
{
self.layer.borderColor = ((UIColor*)[buttonConfig objectForKey:@"borderColor"]).CGColor;
}
if ([buttonConfig objectForKey:@"textColor"])
{
[self setTitleColor:[buttonConfig objectForKey:@"textColor"] forState:UIControlStateNormal];
}
}
#pragma mark - Helpers
- (UIColor *)darkerColorForColor:(UIColor *)color
{
CGFloat r, g, b, a;
if ([color getRed:&r green:&g blue:&b alpha:&a])
return [UIColor colorWithRed:MAX(r - 0.2f, 0.0f)
green:MAX(g - 0.2f, 0.0f)
blue:MAX(b - 0.2f, 0.0f)
alpha:a];
return nil;
}
- (UIColor *)lighterColorForColor:(UIColor *)color
{
CGFloat r, g, b, a;
if ([color getRed:&r green:&g blue:&b alpha:&a])
return [UIColor colorWithRed:MIN(r + 0.2f, 1.0f)
green:MIN(g + 0.2f, 1.0f)
blue:MIN(b + 0.2f, 1.0f)
alpha:a];
return nil;
}
@end