This repository has been archived by the owner on Jun 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathChameleonShorthand.swift
executable file
·337 lines (247 loc) · 8.54 KB
/
ChameleonShorthand.swift
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
// ChameleonShorthand.swift
/*
The MIT License (MIT)
Copyright (c) 2014-2015 Vicc Alexander.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
import UIKit
// MARK: - UIColor Methods Shorthand
/**
Creates and returns a complementary flat color object 180 degrees away in the HSB colorspace from the specified color.
- parameter color: The color whose complementary color is being requested.
- returns: A flat UIColor object in the HSB colorspace.
*/
public func ComplementaryFlatColorOf(_ color: UIColor) -> UIColor {
return UIColor(complementaryFlatColorOf: color)
}
/**
Returns a randomly generated flat color object with an alpha value of 1.0 in either a light or dark shade.
- parameter shade: Specifies whether the randomly generated flat color should be a light or dark shade.
- returns: A flat UIColor object in the HSB colorspace.
*/
public func RandomFlatColorWithShade(_ shade: UIShadeStyle) -> UIColor {
return UIColor(randomFlatColorOf: shade)
}
/**
Creates and returns either a black or white color object depending on which contrasts more with a specified color.
- parameter backgroundColor: The specified color of the contrast color that is being requested.
- parameter returnFlat: Pass **true** to return flat color objects.
- returns: A UIColor object in the HSB colorspace.
*/
public func ContrastColorOf(_ backgroundColor: UIColor, returnFlat: Bool) -> UIColor {
return UIColor(contrastingBlackOrWhiteColorOn: backgroundColor, isFlat: returnFlat)
}
/**
Creates and returns a gradient as a color object with an alpha value of 1.0
- parameter gradientStyle: Specifies the style and direction of the gradual blend between colors.
- parameter frame: The frame rectangle, which describes the view’s location and size in its superview’s coordinate system.
- parameter colors: An array of color objects used to create a gradient.
- returns: A UIColor object using colorWithPattern.
*/
public func GradientColor(_ gradientStyle: UIGradientStyle, frame: CGRect, colors: [UIColor]) -> UIColor {
return UIColor(gradientStyle: gradientStyle, withFrame: frame, andColors: colors)
}
public func HexColor(_ hexString: String, _ alpha: CGFloat = 1.0) -> UIColor? {
return UIColor(hexString: hexString, withAlpha: alpha)
}
/**
Returns the average color generated by averaging the colors of a specified image.
- parameter image: A specified UIImage.
- returns: A flat UIColor object in the HSB colorspace.
*/
public func AverageColorFromImage(_ image: UIImage) -> UIColor {
return UIColor(averageColorFrom: image)
}
// MARK: - Array Methods Shorthand
// TODO Array Extension needed ;)
/**
Generates and creates an array of 5 color objects in the HSB colorspace from the specified color.
- parameter colorSchemeType: The color scheme with which to select colors using a specified color.
- parameter color: The specified color which the color scheme is built around.
- parameter isFlatScheme: Pass *true* to return flat color objects.
- returns: An array of 5 color objects in the HSB colorspace.
*/
public func ColorSchemeOf(_ colorSchemeType:ColorScheme, color:UIColor, isFlatScheme:Bool) -> [UIColor] {
return NSArray(ofColorsWith: colorSchemeType, using: color, withFlatScheme: isFlatScheme) as! [UIColor]
}
/**
Generates and creates an array of 5 color objects in the HSB colorspace that appear most often in a specified image.
- parameter image: The specified image which the color scheme is built around.
- parameter withFlatScheme: Pass **true** to return flat color objects.
- returns: An array of 5 color objects in the HSB colorspace.
*/
public func ColorsFromImage(_ image: UIImage, withFlatScheme: Bool) -> [UIColor] {
// TODO: Remove forced casting
return NSArray(ofColorsFrom: image, withFlatScheme: withFlatScheme) as! [UIColor]
}
// MARK: - Special Colors Shorthand
/**
Returns a randomly generated flat color object whose alpha value is 1.0.
- returns: A flat UIColor object in the HSB colorspace.
*/
public func RandomFlatColor() -> UIColor {
return UIColor.randomFlat
}
public func ClearColor() -> UIColor {
return UIColor.clear
}
// MARK: - Light Shades Shorthand
public func FlatBlack() -> UIColor {
return UIColor.flatBlack
}
public func FlatBlue() -> UIColor {
return UIColor.flatBlue
}
public func FlatBrown() -> UIColor {
return UIColor.flatBrown
}
public func FlatCoffee() -> UIColor {
return UIColor.flatCoffee
}
public func FlatForestGreen() -> UIColor {
return UIColor.flatForestGreen
}
public func FlatGray() -> UIColor {
return UIColor.flatGray
}
public func FlatGreen() -> UIColor {
return UIColor.flatGreen
}
public func FlatLime() -> UIColor {
return UIColor.flatLime
}
public func FlatMagenta() -> UIColor {
return UIColor.flatMagenta
}
public func FlatMaroon() -> UIColor {
return UIColor.flatMaroon
}
public func FlatMint() -> UIColor {
return UIColor.flatMint
}
public func FlatNavyBlue() -> UIColor {
return UIColor.flatNavyBlue
}
public func FlatOrange() -> UIColor {
return UIColor.flatOrange
}
public func FlatPink() -> UIColor {
return UIColor.flatPink
}
public func FlatPlum() -> UIColor {
return UIColor.flatPlum
}
public func FlatPowderBlue() -> UIColor {
return UIColor.flatPowderBlue
}
public func FlatPurple() -> UIColor {
return UIColor.flatPurple
}
public func FlatRed() -> UIColor {
return UIColor.flatRed
}
public func FlatSand() -> UIColor {
return UIColor.flatSand
}
public func FlatSkyBlue() -> UIColor {
return UIColor.flatSkyBlue
}
public func FlatTeal() -> UIColor {
return UIColor.flatTeal
}
public func FlatWatermelon() -> UIColor {
return UIColor.flatWatermelon
}
public func FlatWhite() -> UIColor {
return UIColor.flatWhite
}
public func FlatYellow() -> UIColor {
return UIColor.flatYellow
}
// MARK: - Chameleon - Dark Shades Shorthand
public func FlatBlackDark() -> UIColor {
return UIColor.flatBlackDark
}
public func FlatBlueDark() -> UIColor {
return UIColor.flatBlueDark
}
public func FlatBrownDark() -> UIColor {
return UIColor.flatBrownDark
}
public func FlatCoffeeDark() -> UIColor {
return UIColor.flatCoffeeDark
}
public func FlatForestGreenDark() -> UIColor {
return UIColor.flatForestGreenDark
}
public func FlatGrayDark() -> UIColor {
return UIColor.flatGrayDark
}
public func FlatGreenDark() -> UIColor {
return UIColor.flatGreenDark
}
public func FlatLimeDark() -> UIColor {
return UIColor.flatLimeDark
}
public func FlatMagentaDark() -> UIColor {
return UIColor.flatMagentaDark
}
public func FlatMaroonDark() -> UIColor {
return UIColor.flatMaroonDark
}
public func FlatMintDark() -> UIColor {
return UIColor.flatMintDark
}
public func FlatNavyBlueDark() -> UIColor {
return UIColor.flatNavyBlueDark
}
public func FlatOrangeDark() -> UIColor {
return UIColor.flatOrangeDark
}
public func FlatPinkDark() -> UIColor {
return UIColor.flatPinkDark
}
public func FlatPlumDark() -> UIColor {
return UIColor.flatPlumDark
}
public func FlatPowderBlueDark() -> UIColor {
return UIColor.flatPowderBlueDark
}
public func FlatPurpleDark() -> UIColor {
return UIColor.flatPurpleDark
}
public func FlatRedDark() -> UIColor {
return UIColor.flatRedDark
}
public func FlatSandDark() -> UIColor {
return UIColor.flatSandDark
}
public func FlatSkyBlueDark() -> UIColor {
return UIColor.flatSkyBlueDark
}
public func FlatTealDark() -> UIColor {
return UIColor.flatTealDark
}
public func FlatWatermelonDark() -> UIColor {
return UIColor.flatWatermelonDark
}
public func FlatWhiteDark() -> UIColor {
return UIColor.flatWhiteDark
}
public func FlatYellowDark() -> UIColor {
return UIColor.flatYellowDark
}