-
Notifications
You must be signed in to change notification settings - Fork 0
/
UIColor+FlatUI.m
executable file
·148 lines (117 loc) · 4.19 KB
/
UIColor+FlatUI.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
143
144
145
146
147
148
//
// UIColor+FlatUI.m
// FlatUI
//
// Created by Jack Flintermann on 5/3/13.
// Copyright (c) 2013 Jack Flintermann. All rights reserved.
//
#import "UIColor+FlatUI.h"
@implementation UIColor (FlatUI)
// Thanks to http://stackoverflow.com/questions/3805177/how-to-convert-hex-rgb-color-codes-to-uicolor
+ (UIColor *) colorFromHexCode:(NSString *)hexString {
NSString *cleanString = [hexString stringByReplacingOccurrencesOfString:@"#" withString:@""];
if ([cleanString length] == 3) {
cleanString = [NSString stringWithFormat:@"%@%@%@%@%@%@",
[cleanString substringWithRange:NSMakeRange(0, 1)],[cleanString substringWithRange:NSMakeRange(0, 1)],
[cleanString substringWithRange:NSMakeRange(1, 1)],[cleanString substringWithRange:NSMakeRange(1, 1)],
[cleanString substringWithRange:NSMakeRange(2, 1)],[cleanString substringWithRange:NSMakeRange(2, 1)]];
}
if([cleanString length] == 6) {
cleanString = [cleanString stringByAppendingString:@"ff"];
}
unsigned int baseValue;
[[NSScanner scannerWithString:cleanString] scanHexInt:&baseValue];
float red = ((baseValue >> 24) & 0xFF)/255.0f;
float green = ((baseValue >> 16) & 0xFF)/255.0f;
float blue = ((baseValue >> 8) & 0xFF)/255.0f;
float alpha = ((baseValue >> 0) & 0xFF)/255.0f;
return [UIColor colorWithRed:red green:green blue:blue alpha:alpha];
}
+ (UIColor *) turquoiseColor {
return [UIColor colorFromHexCode:@"1ABC9C"];
}
+ (UIColor *) greenSeaColor {
return [UIColor colorFromHexCode:@"16A085"];
}
//FF7777 16A085
+ (UIColor *) emerlandColor {
return [UIColor colorFromHexCode:@"2ECC71"];
}
+ (UIColor *) myblue {
return [UIColor colorFromHexCode:@"9CD2F6"];
}
+ (UIColor *) nephritisColor {
return [UIColor colorFromHexCode:@"27AE60"];
}
+ (UIColor *) peterRiverColor {
return [UIColor colorFromHexCode:@"3498DB"];
}
+ (UIColor *) belizeHoleColor {
return [UIColor colorFromHexCode:@"2980B9"];
}
+ (UIColor *) amethystColor {
return [UIColor colorFromHexCode:@"9B59B6"];
}
+ (UIColor *) wisteriaColor {
return [UIColor colorFromHexCode:@"8E44AD"];
}
+ (UIColor *) wetAsphaltColor {
return [UIColor colorFromHexCode:@"34495E"];
}
+ (UIColor *) midnightBlueColor {
return [UIColor colorFromHexCode:@"2C3E50"];
}
+ (UIColor *) sunflowerColor {
return [UIColor colorFromHexCode:@"F1C40F"];
}
+ (UIColor *) tangerineColor {
return [UIColor colorFromHexCode:@"F39C12"];
}
+ (UIColor *) carrotColor {
return [UIColor colorFromHexCode:@"E67E22"];
}
+ (UIColor *) pumpkinColor {
return [UIColor colorFromHexCode:@"D35400"];
}
+ (UIColor *) alizarinColor {
return [UIColor colorFromHexCode:@"E74C3C"];
}
+ (UIColor *) pomegranateColor {
return [UIColor colorFromHexCode:@"C0392B"];
}
+ (UIColor *) cloudsColor {
return [UIColor colorFromHexCode:@"ECF0F1"];
}
+ (UIColor *) silverColor {
return [UIColor colorFromHexCode:@"BDC3C7"];
}
+ (UIColor *) concreteColor {
return [UIColor colorFromHexCode:@"95A5A6"];
}
+ (UIColor *) asbestosColor {
return [UIColor colorFromHexCode:@"7F8C8D"];
}
+ (UIColor *) blendedColorWithForegroundColor:(UIColor *)foregroundColor
backgroundColor:(UIColor *)backgroundColor
percentBlend:(CGFloat) percentBlend {
CGFloat onRed, offRed, newRed, onGreen, offGreen, newGreen, onBlue, offBlue, newBlue, onWhite, offWhite;
if ([foregroundColor getWhite:&onWhite alpha:nil]) {
onRed = onWhite;
onBlue = onWhite;
onGreen = onWhite;
} else {
[foregroundColor getRed:&onRed green:&onGreen blue:&onBlue alpha:nil];
}
if ([backgroundColor getWhite:&offWhite alpha:nil]) {
offRed = offWhite;
offBlue = offWhite;
offGreen = offWhite;
} else {
[backgroundColor getRed:&offRed green:&offGreen blue:&offBlue alpha:nil];
}
newRed = onRed * percentBlend + offRed * (1-percentBlend);
newGreen = onGreen * percentBlend + offGreen * (1-percentBlend);
newBlue = onBlue * percentBlend + offBlue * (1-percentBlend);
return [UIColor colorWithRed:newRed green:newGreen blue:newBlue alpha:1.0];
}
@end