10 | #import "ChameleonEnums.h"
11 |
12 | @interface UIViewController (Chameleon)
13 |
14 | /**
15 | * Sets the color theme for the specified view controller using a primary color and the specified content style.
16 | *
17 | * @param primaryColor The primary color.
18 | * @param contentStyle The contentStyle.
19 | *
20 | * @since 2.0
21 | */
22 | - (void)setThemeUsingPrimaryColor:(UIColor *)primaryColor
23 | withContentStyle:(UIContentStyle)contentStyle;
24 |
25 | /**
26 | * Sets the color theme for the specified view controller using a primary color, secondary color, and the specified content style.
27 | *
28 | * @param primaryColor The primary color.
29 | * @param secondaryColor The secondary color.
30 | * @param contentStyle The contentStyle.
31 | *
32 | * @since 2.0
33 | */
34 | - (void)setThemeUsingPrimaryColor:(UIColor *)primaryColor
35 | withSecondaryColor:(UIColor *)secondaryColor
36 | andContentStyle:(UIContentStyle)contentStyle;
37 |
38 | /**
39 | * Sets the color theme for the specified view controller using a primary color, secondary color, font name, and the specified content style.
40 | *
41 | * @param primaryColor The primary color.
42 | * @param secondaryColor The secondary color.
43 | * @param fontName The main font to use for all text-based elements.
44 | * @param contentStyle The contentStyle.
45 | *
46 | * @since 2.0
47 | */
48 | - (void)setThemeUsingPrimaryColor:(UIColor *)primaryColor
49 | withSecondaryColor:(UIColor *)secondaryColor
50 | usingFontName:(NSString *)fontName
51 | andContentStyle:(UIContentStyle)contentStyle;
52 |
53 | /**
54 | * Sets the status bar style for the specified @c UIViewController and all its child controllers.
55 | *
56 | * @param statusBarStyle The style of the device's status bar.
57 | *
58 | * @note Chameleon introduces a new @c statusBarStyle called @c UIStatusBarStyleContrast.
59 | *
60 | * @since 2.0
61 | */
62 | - (void)setStatusBarStyle:(UIStatusBarStyle)statusBarStyle;
63 |
64 | @end
65 |
--------------------------------------------------------------------------------
/Pod/Classes/Swift/ChameleonShorthand.swift:
--------------------------------------------------------------------------------
1 |
2 | // ChameleonShorthand.swift
3 |
4 | /*
5 |
6 | The MIT License (MIT)
7 |
8 | Copyright (c) 2014-2015 Vicc Alexander.
9 |
10 | Permission is hereby granted, free of charge, to any person obtaining a copy
11 | of this software and associated documentation files (the "Software"), to deal
12 | in the Software without restriction, including without limitation the rights
13 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 | copies of the Software, and to permit persons to whom the Software is
15 | furnished to do so, subject to the following conditions:
16 |
17 | The above copyright notice and this permission notice shall be included in all
18 | copies or substantial portions of the Software.
19 |
20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 | SOFTWARE.
27 |
28 | */
29 |
30 | import UIKit
31 |
32 | // MARK: - UIColor Methods Shorthand
33 |
34 | /**
35 | Creates and returns a complementary flat color object 180 degrees away in the HSB colorspace from the specified color.
36 |
37 | - parameter color: The color whose complementary color is being requested.
38 |
39 | - returns: A flat UIColor object in the HSB colorspace.
40 | */
41 | public func ComplementaryFlatColorOf(_ color: UIColor) -> UIColor {
42 | return UIColor(complementaryFlatColorOf: color)
43 | }
44 |
45 | /**
46 | Returns a randomly generated flat color object with an alpha value of 1.0 in either a light or dark shade.
47 |
48 | - parameter shade: Specifies whether the randomly generated flat color should be a light or dark shade.
49 |
50 | - returns: A flat UIColor object in the HSB colorspace.
51 | */
52 | public func RandomFlatColorWithShade(_ shade: UIShadeStyle) -> UIColor {
53 | return UIColor(randomFlatColorOf: shade)
54 | }
55 |
56 | /**
57 | Creates and returns either a black or white color object depending on which contrasts more with a specified color.
58 |
59 | - parameter backgroundColor: The specified color of the contrast color that is being requested.
60 | - parameter returnFlat: Pass **true** to return flat color objects.
61 |
62 | - returns: A UIColor object in the HSB colorspace.
63 | */
64 | public func ContrastColorOf(_ backgroundColor: UIColor, returnFlat: Bool) -> UIColor {
65 | return UIColor(contrastingBlackOrWhiteColorOn: backgroundColor, isFlat: returnFlat)
66 | }
67 |
68 | /**
69 | Creates and returns a gradient as a color object with an alpha value of 1.0
70 |
71 | - parameter gradientStyle: Specifies the style and direction of the gradual blend between colors.
72 | - parameter frame: The frame rectangle, which describes the view’s location and size in its superview’s coordinate system.
73 | - parameter colors: An array of color objects used to create a gradient.
74 |
75 | - returns: A UIColor object using colorWithPattern.
76 | */
77 | public func GradientColor(_ gradientStyle: UIGradientStyle, frame: CGRect, colors: [UIColor]) -> UIColor {
78 | return UIColor(gradientStyle: gradientStyle, withFrame: frame, andColors: colors)
79 | }
80 |
81 | public func HexColor(_ hexString: String, _ alpha: CGFloat = 1.0) -> UIColor? {
82 | return UIColor(hexString: hexString, withAlpha: alpha)
83 | }
84 |
85 | /**
86 | Returns the average color generated by averaging the colors of a specified image.
87 |
88 | - parameter image: A specified UIImage.
89 |
90 | - returns: A flat UIColor object in the HSB colorspace.
91 | */
92 | public func AverageColorFromImage(_ image: UIImage) -> UIColor {
93 | return UIColor(averageColorFrom: image)
94 | }
95 |
96 | // MARK: - Array Methods Shorthand
97 |
98 | // TODO Array Extension needed ;)
99 |
100 | /**
101 | Generates and creates an array of 5 color objects in the HSB colorspace from the specified color.
102 |
103 | - parameter colorSchemeType: The color scheme with which to select colors using a specified color.
104 | - parameter color: The specified color which the color scheme is built around.
105 | - parameter isFlatScheme: Pass *true* to return flat color objects.
106 |
107 | - returns: An array of 5 color objects in the HSB colorspace.
108 | */
109 | public func ColorSchemeOf(_ colorSchemeType:ColorScheme, color:UIColor, isFlatScheme:Bool) -> [UIColor] {
110 | return NSArray(ofColorsWith: colorSchemeType, using: color, withFlatScheme: isFlatScheme) as! [UIColor]
111 | }
112 |
113 | /**
114 | Generates and creates an array of 5 color objects in the HSB colorspace that appear most often in a specified image.
115 |
116 | - parameter image: The specified image which the color scheme is built around.
117 | - parameter withFlatScheme: Pass **true** to return flat color objects.
118 |
119 | - returns: An array of 5 color objects in the HSB colorspace.
120 | */
121 | public func ColorsFromImage(_ image: UIImage, withFlatScheme: Bool) -> [UIColor] {
122 | // TODO: Remove forced casting
123 | return NSArray(ofColorsFrom: image, withFlatScheme: withFlatScheme) as! [UIColor]
124 | }
125 |
126 |
127 | // MARK: - Special Colors Shorthand
128 |
129 | /**
130 | Returns a randomly generated flat color object whose alpha value is 1.0.
131 |
132 | - returns: A flat UIColor object in the HSB colorspace.
133 | */
134 | public func RandomFlatColor() -> UIColor {
135 | return UIColor.randomFlat
136 | }
137 |
138 | public func ClearColor() -> UIColor {
139 | return UIColor.clear
140 | }
141 |
142 |
143 | // MARK: - Light Shades Shorthand
144 |
145 | public func FlatBlack() -> UIColor {
146 | return UIColor.flatBlack
147 | }
148 |
149 | public func FlatBlue() -> UIColor {
150 | return UIColor.flatBlue
151 | }
152 |
153 | public func FlatBrown() -> UIColor {
154 | return UIColor.flatBrown
155 | }
156 |
157 | public func FlatCoffee() -> UIColor {
158 | return UIColor.flatCoffee
159 | }
160 |
161 | public func FlatForestGreen() -> UIColor {
162 | return UIColor.flatForestGreen
163 | }
164 |
165 | public func FlatGray() -> UIColor {
166 | return UIColor.flatGray
167 | }
168 |
169 | public func FlatGreen() -> UIColor {
170 | return UIColor.flatGreen
171 | }
172 |
173 | public func FlatLime() -> UIColor {
174 | return UIColor.flatLime
175 | }
176 |
177 | public func FlatMagenta() -> UIColor {
178 | return UIColor.flatMagenta
179 | }
180 |
181 | public func FlatMaroon() -> UIColor {
182 | return UIColor.flatMaroon
183 | }
184 |
185 | public func FlatMint() -> UIColor {
186 | return UIColor.flatMint
187 | }
188 |
189 | public func FlatNavyBlue() -> UIColor {
190 | return UIColor.flatNavyBlue
191 | }
192 |
193 | public func FlatOrange() -> UIColor {
194 | return UIColor.flatOrange
195 | }
196 |
197 | public func FlatPink() -> UIColor {
198 | return UIColor.flatPink
199 | }
200 |
201 | public func FlatPlum() -> UIColor {
202 | return UIColor.flatPlum
203 | }
204 |
205 | public func FlatPowderBlue() -> UIColor {
206 | return UIColor.flatPowderBlue
207 | }
208 |
209 | public func FlatPurple() -> UIColor {
210 | return UIColor.flatPurple
211 | }
212 |
213 | public func FlatRed() -> UIColor {
214 | return UIColor.flatRed
215 | }
216 |
217 | public func FlatSand() -> UIColor {
218 | return UIColor.flatSand
219 | }
220 |
221 | public func FlatSkyBlue() -> UIColor {
222 | return UIColor.flatSkyBlue
223 | }
224 |
225 | public func FlatTeal() -> UIColor {
226 | return UIColor.flatTeal
227 | }
228 |
229 | public func FlatWatermelon() -> UIColor {
230 | return UIColor.flatWatermelon
231 | }
232 |
233 | public func FlatWhite() -> UIColor {
234 | return UIColor.flatWhite
235 | }
236 |
237 | public func FlatYellow() -> UIColor {
238 | return UIColor.flatYellow
239 | }
240 |
241 | // MARK: - Chameleon - Dark Shades Shorthand
242 |
243 | public func FlatBlackDark() -> UIColor {
244 | return UIColor.flatBlackDark
245 | }
246 |
247 | public func FlatBlueDark() -> UIColor {
248 | return UIColor.flatBlueDark
249 | }
250 |
251 | public func FlatBrownDark() -> UIColor {
252 | return UIColor.flatBrownDark
253 | }
254 |
255 | public func FlatCoffeeDark() -> UIColor {
256 | return UIColor.flatCoffeeDark
257 | }
258 |
259 | public func FlatForestGreenDark() -> UIColor {
260 | return UIColor.flatForestGreenDark
261 | }
262 |
263 | public func FlatGrayDark() -> UIColor {
264 | return UIColor.flatGrayDark
265 | }
266 |
267 | public func FlatGreenDark() -> UIColor {
268 | return UIColor.flatGreenDark
269 | }
270 |
271 | public func FlatLimeDark() -> UIColor {
272 | return UIColor.flatLimeDark
273 | }
274 |
275 | public func FlatMagentaDark() -> UIColor {
276 | return UIColor.flatMagentaDark
277 | }
278 |
279 | public func FlatMaroonDark() -> UIColor {
280 | return UIColor.flatMaroonDark
281 | }
282 |
283 | public func FlatMintDark() -> UIColor {
284 | return UIColor.flatMintDark
285 | }
286 |
287 | public func FlatNavyBlueDark() -> UIColor {
288 | return UIColor.flatNavyBlueDark
289 | }
290 |
291 | public func FlatOrangeDark() -> UIColor {
292 | return UIColor.flatOrangeDark
293 | }
294 |
295 | public func FlatPinkDark() -> UIColor {
296 | return UIColor.flatPinkDark
297 | }
298 |
299 | public func FlatPlumDark() -> UIColor {
300 | return UIColor.flatPlumDark
301 | }
302 |
303 | public func FlatPowderBlueDark() -> UIColor {
304 | return UIColor.flatPowderBlueDark
305 | }
306 |
307 | public func FlatPurpleDark() -> UIColor {
308 | return UIColor.flatPurpleDark
309 | }
310 |
311 | public func FlatRedDark() -> UIColor {
312 | return UIColor.flatRedDark
313 | }
314 |
315 | public func FlatSandDark() -> UIColor {
316 | return UIColor.flatSandDark
317 | }
318 |
319 | public func FlatSkyBlueDark() -> UIColor {
320 | return UIColor.flatSkyBlueDark
321 | }
322 |
323 | public func FlatTealDark() -> UIColor {
324 | return UIColor.flatTealDark
325 | }
326 |
327 | public func FlatWatermelonDark() -> UIColor {
328 | return UIColor.flatWatermelonDark
329 | }
330 |
331 | public func FlatWhiteDark() -> UIColor {
332 | return UIColor.flatWhiteDark
333 | }
334 |
335 | public func FlatYellowDark() -> UIColor {
336 | return UIColor.flatYellowDark
337 | }
338 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | ## Swift 3
16 |
17 | To use the Swift 3 version, add this to your Podfile (until 2.2 or higher is released):
18 | ```ruby
19 | pod 'ChameleonFramework/Swift', :git => 'https://github.com/ViccAlexander/Chameleon.git'
20 | ```
21 |
22 | ## Introduction
23 |
24 | **Chameleon** is a lightweight, yet powerful, color framework for iOS (Objective-C & Swift). It is built on the idea that software applications should function effortlessly while simultaneously maintaining their beautiful interfaces.
25 |
26 | With Chameleon, you can easily stop tinkering with RGB values, wasting hours figuring out the right color combinations to use in your app, and worrying about whether your text will be readable on the various background colors of your app.
27 |
28 | ### Features
29 |
30 |
31 |
32 |
33 |
34 | ### App Showcase
35 |
36 | ###### In an upcoming update we'll begin showcasing some of the best apps and companies making use of Chameleon. If you'd like to see your app featured in this section, make sure to add it [here](https://airtable.com/shrr1WK6dLQBZfXV0).
37 |
38 | ## Table of Contents
39 | [● Product Features](https://github.com/ViccAlexander/Chameleon#-product-features)
40 | [● Requirements](https://github.com/ViccAlexander/Chameleon#%EF%B8%8F-requirements)
41 | [● License](https://github.com/ViccAlexander/Chameleon#-license)
42 | [● Contributions](https://github.com/ViccAlexander/Chameleon#-contributions)
43 | [● Documentation](https://github.com/ViccAlexander/Chameleon#-documentation)
44 | [● Storyboard Add-On](https://github.com/ViccAlexander/Chameleon#storyboard-add-on)
45 | [● Author](https://github.com/ViccAlexander/Chameleon#-author)
46 | [● To Do List](https://github.com/ViccAlexander/Chameleon#-to-do-list)
47 | [● Change Log](https://github.com/ViccAlexander/Chameleon#-change-log)
48 |
49 | ## 🌟 Product Features
50 |
51 | ### 100% Flat & Gorgeous
52 |
53 | Chameleon features over 24 hand-picked colors that come in both light and dark shades.
54 |
55 |
56 |
57 |
58 |
59 | ### Flat Color Schemes
60 |
61 | Chameleon equips you with 3 different classes of flat color schemes that can be generated from a flat or non-flat color. *In the examples below, the white stars indicate the color used to generate the schemes.*
62 |
63 | ###### Analogous Flat Color Scheme
64 |
65 |
66 |
67 |
68 |
69 | ###### Complementary Flat Color Scheme
70 |
71 |
72 |
73 |
74 | ###### Triadic Flat Color Scheme
75 |
76 |
77 |
78 |
79 | ### Contrasting Text
80 | With a plethora of color choices available for text, it's difficult to choose one that all users will appreciate and be able to read. Whether you're in doubt of your text and tint color choices, or afraid to let users customize their profile colors because it may disturb the legibility or usability of the app, you no longer have to worry. With Chameleon, you can ensure that all text stands out independent of the background color.
81 |
82 | Oh... Chameleon works with the status bar as well. : )
83 |
84 |
85 |
86 |
87 |
88 | ### Themes 
89 |
90 | Chameleon now allows you easily theme your app with as little as **one line of code**. You can set a theme for all your views, and for specific views as well.
91 |
92 |
93 |
94 |
95 |
96 | ### Colors From Images
97 |
98 | Chameleon allows you to seamlessly extract non-flat or flat color schemes from images without hassle. You can also generate the average color from an image with ease. You can now mold the UI colors of a profile, or product based on an image!
99 |
100 |
101 |
102 |
103 |
104 | ### Gradient Colors
105 | With iOS 7 & 8, Apple mainstreamed flat colors. Now, with the release of iOS 9, Chameleon strives to elevate the game once more. Say hello to gradient colors. Using one line of code, you can easily set any object's color properties to a gradient (background colors, text colors, tint colors, etc). Other features, like Chameleon's contrasting feature, can also be applied to create a seamless product. Experimentation is encouraged, and gutsiness is applauded!
106 |
107 |
108 |
109 |
110 |
111 | 
112 |
113 | ### Xcode Quick Help Documentation
114 |
115 | Chameleon's documentation, while written as clearly and concisely as possible may still render some slightly confused. But don't fret! Staying true to our vision of simplifying the entire color process, we added Xcode Quick Help's Documentation Support! Simply highlight a Chameleon method or tap it with three fingers to find out more about what it is and what it does!
116 |
117 |
118 |
119 |
120 |
121 | ### Palettes
122 |
123 | If you're like us and love to use storyboards, Chameleon's got you covered. We've provided you with a quick and easy way to access Chameleon colors right from Storyboard, and any other app that uses the color picker (i.e. TextEdit). In addition you can even import the palette directly into Photoshop and Sketch.
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 | ## ⚠️ Requirements
134 |
135 | * Objective-C or Swift
136 | * Requires a minimum of iOS 7.0 for Objective-C (No active development for anything earlier, but may work with 6.0) and a minimum of iOS 8.0 for Swift.
137 | * Requires Xcode 6.3 for use in any iOS Project
138 |
139 | ## 🔑 License
140 | Chameleon is released and distributed under the terms and conditions of the [MIT license](https://github.com/ViccAlexander/Chameleon/blob/master/LICENSE.md).
141 |
142 | ## 👥 Contributions
143 | If you run into problems, please open up an issue. We also actively welcome pull requests. By contributing to Chameleon you agree that your contributions will be licensed under its MIT license.
144 |
145 | If you use Chameleon in your app we would love to hear about it! Drop Vicc a line on [twitter](http://twitter.com/viccsmind).
146 |
147 | ## 📗 Documentation
148 | All methods, properties, and types available in Chameleon are documented below.
149 |
150 | ##### Documentation Table of Contents
151 | [● Installation](https://github.com/ViccAlexander/Chameleon#installation)
152 | [● Palettes](https://github.com/ViccAlexander/Chameleon#palettes)
153 | [● Usage](https://github.com/ViccAlexander/Chameleon#usage)
154 | [● UIColor Methods](https://github.com/ViccAlexander/Chameleon#uicolor-methods)
155 | [● Colors From Images](https://github.com/ViccAlexander/Chameleon#colors-from-images)
156 | [● UIStatusBarStyle Methods](https://github.com/ViccAlexander/Chameleon#uistatusbarstyle-methods)
157 | [● Color Scheme Methods](https://github.com/ViccAlexander/Chameleon#color-schemes-methods)
158 | [● Theme Methods](https://github.com/ViccAlexander/Chameleon#theme-methods)
159 |
160 | ### Installation
161 |
162 | ###### Note: Swift 3 version maintained in a separate branch until it's release.
163 |
164 | #### CocoaPods Installation
165 | Chameleon is now available on [CocoaPods](http://cocoapods.org). Simply add the following to your project Podfile, and you'll be good to go.
166 |
167 | ###### Objective-C
168 | ```ruby
169 | use_frameworks!
170 |
171 | pod 'ChameleonFramework'
172 | ```
173 | ###### Swift
174 | ```ruby
175 | use_frameworks!
176 |
177 | pod 'ChameleonFramework/Swift'
178 | ```
179 |
180 | =======
181 | #### Carthage Installation
182 | Add this to your Cartfile:
183 | ```ruby
184 | github "ViccAlexander/Chameleon"
185 | ```
186 |
187 | =======
188 | #### Manual Installation
189 | If you rather install this framework manually, just drag and drop the Chameleon folder into your project, and make sure you check the following boxes. Note: Don't forget to manually import the *QuartzCore* & *CoreGraphics* framework if you plan on using gradient colors!
190 |
191 |
192 |
193 |
194 |
195 | If you're working with Swift and are manually installing Chameleon, there's an additional step. Make sure to download and drag the following file, [ChameleonShorthand.swift](https://github.com/ViccAlexander/Chameleon/blob/master/Pod/Classes/Swift/ChameleonShorthand.swift), into your project, and you'll be good to go.
196 |
197 | #### Palettes
198 | ##### Storyboard Add-On
199 | Using Chameleon's awesome palette in Storyboard is easy! Simply download and install [Chameleon Palette](https://github.com/ViccAlexander/Chameleon/blob/master/Extras/Chameleon.dmg?raw=true).
200 |
201 | Once installed, make sure to restart Xcode. You'll find all of Chameleon's colors in the Palette Color Picker whenever they're needed! :)
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 | ##### Photoshop Add-On
212 | Using Chameleon's awesome palette in Sketch is easy! Simply download and install [Photoshop Palette](https://github.com/ViccAlexander/Chameleon/blob/master/Extras/Chameleon_Photoshop.aco?raw=true).
213 |
214 | ##### Sketch Add-On
215 | Using Chameleon's awesome palette in Sketch is easy! Simply download and install [Sketch Palette](https://github.com/ViccAlexander/Chameleon/blob/master/Extras/Chameleon.sketchpalette?raw=true).
216 |
217 | ### Usage
218 | To use the myriad of features in Chameleon, include the following import:
219 |
220 | ###### If you installed Chameleon using CocoaPods:
221 |
222 | ###### Objective-C
223 |
224 | ``` objective-c
225 | #import
226 | ```
227 |
228 | ###### Swift:
229 | ``` swift
230 | import ChameleonFramework
231 | ```
232 |
233 | ###### If you installed Chameleon using Carthage:
234 |
235 | ``` swift
236 | import Chameleon
237 | ```
238 |
239 | ###### If you installed Chameleon manually:
240 | ``` objective-c
241 | #import "Chameleon.h"
242 | ```
243 | ### UIColor Methods
244 | [● Flat Colors](https://github.com/ViccAlexander/Chameleon#flat-colors)
245 | [● Random Colors](https://github.com/ViccAlexander/Chameleon#random-colors)
246 | [● Complementary Colors](https://github.com/ViccAlexander/Chameleon#complementary-colors)
247 | [● Contrasting Colors](https://github.com/ViccAlexander/Chameleon#contrasting-colors)
248 | [● Flattening Non-Flat Colors](https://github.com/ViccAlexander/Chameleon#flattening-non-flat-colors)
249 | [● Gradient Colors](https://github.com/ViccAlexander/Chameleon#gradient-colors-1)
250 | [● Hex Colors](https://github.com/ViccAlexander/Chameleon#hex-colors-)
251 | [● Lighter & Darker Colors](https://github.com/ViccAlexander/Chameleon#lighter-and-darker-colors-)
252 |
253 | #### Flat Colors
254 | Using a flat color is as easy as adding any other color in your app (if not easier). For example, to set a view's background property to a flat color with a dark shade, you simply have to do the following:
255 |
256 | ##### Normal Convention:
257 |
258 | ###### Objective-C
259 | ``` objective-c
260 | self.view.backgroundColor = [UIColor flatGreenColorDark];
261 | ```
262 | ###### Swift
263 | ``` swift
264 | view.backgroundColor = UIColor.flatGreenDark
265 | ```
266 |
267 | ##### Chameleon Shorthand:
268 |
269 | ###### Objective-C
270 | ``` objective-c
271 | self.view.backgroundColor = FlatGreenDark;
272 | ```
273 | ###### Swift
274 | ``` swift
275 | view.backgroundColor = FlatGreenDark()
276 | ```
277 |
278 | Setting the color for a light shade is the same, except without adding the *Dark* suffix. (By default, all colors without a *Dark* suffix are light shades). For example:
279 |
280 | ##### Normal Convention:
281 | ###### Objective-C
282 | ``` objective-c
283 | self.view.backgroundColor = [UIColor flatGreenColor];
284 | ```
285 | ###### Swift
286 | ``` swift
287 | view.backgroundColor = UIColor.flatGreen
288 | ```
289 |
290 | ##### Chameleon Shorthand:
291 |
292 | ###### Objective-C
293 | ``` objective-c
294 | self.view.backgroundColor = FlatGreen;
295 | ```
296 | ###### Swift
297 | ``` swift
298 | view.backgroundColor = FlatGreen()
299 | ```
300 |
301 | #### Random Colors
302 | There are four ways to generate a random flat color. If you have no preference as to whether you want a light shade or a dark shade, you can do the following:
303 |
304 | ##### Normal Convention:
305 | ###### Objective-C
306 | ``` objective-c
307 | self.view.backgroundColor = [UIColor randomFlatColor];
308 | ```
309 | ###### Swift
310 | ``` swift
311 | view.backgroundColor = UIColor.randomFlat
312 | ```
313 |
314 | ##### Chameleon Shorthand:
315 | ###### Objective-C
316 | ``` objective-c
317 | self.view.backgroundColor = RandomFlatColor;
318 | ```
319 |
320 | ###### Swift
321 | ``` swift
322 | view.backgroundColor = RandomFlatColor()
323 | ```
324 |
325 | Otherwise, you can perform the following method call to specify whether it should return either a light or dark shade:
326 |
327 | ##### Normal Convention:
328 | ###### Objective-C
329 | ``` objective-c
330 | [UIColor colorWithRandomFlatColorOfShadeStyle:UIShadeStyleLight];
331 | ```
332 |
333 | ###### Swift
334 | ``` swift
335 | UIColor(randomFlatColorOfShadeStyle:.Light)
336 | ```
337 |
338 | ##### Chameleon Shorthand:
339 | ###### Objective-C
340 | ``` objective-c
341 | RandomFlatColorWithShade(UIShadeStyleLight);
342 | ```
343 | ###### Swift
344 | ``` swift
345 | RandomFlatColorWithShade(.Light)
346 | ```
347 |
348 | **UIShadeStyles:**
349 | - `UIShadeStyleLight` (`UIShadeStyle.Light` in Swift)
350 | - `UIShadeStyleDark` (`UIShadeStyle.Dark` in Swift)
351 |
352 | ##### Choosing A Random Color From a List of Colors 
353 |
354 | If you need to be a bit more selective and only display a random color from a set list of colors, you can use the following method:
355 |
356 | ##### Normal Convention:
357 | ###### Objective-C
358 | ``` objective-c
359 | [UIColor colorWithRandomColorInArray:@[FlatWhite, FlatRed, FlatBlue]];
360 | ```
361 |
362 | ###### Swift
363 | ``` swift
364 | TBA
365 | ```
366 |
367 | ##### Chameleon Shorthand:
368 | ###### Objective-C
369 | ``` objective-c
370 | RandomFlatColorInArray(@[FlatWhite, FlatRed, FlatBlue])
371 | ```
372 | ###### Swift
373 | ``` swift
374 | TBA
375 | ```
376 |
377 | ##### Choosing A Random Flat Color But Excluding A Few 
378 |
379 | Last but certainly not least, you can also choose form the list of random colors and exclude the ones you don't want. For example say you want to randomly select a flat color for a user's profile, but don't want to use any blacks, grays, or whites. You can simply do:
380 |
381 | ##### Normal Convention:
382 | ###### Objective-C
383 | ``` objective-c
384 | [UIColor colorWithRandomFlatColorExcludingColorsInArray:@[FlatBlack, FlatBlackDark, FlatGray, FlatGrayDark, FlatWhite, FlatWhiteDark]];
385 | ```
386 |
387 | ###### Swift
388 | ``` swift
389 | TBA
390 | ```
391 |
392 | ##### Chameleon Shorthand:
393 | ###### Objective-C
394 | ``` objective-c
395 | RandomFlatColorExcluding(@[FlatBlack, FlatBlackDark, FlatGray, FlatGrayDark, FlatWhite, FlatWhiteDark])
396 | ```
397 | ###### Swift
398 | ``` swift
399 | TBA
400 | ```
401 |
402 | #### Complementary Colors
403 | To generate a complementary color, perform the following method call, remembering to specify the color whose complement you want:
404 |
405 | ##### Normal Convention:
406 | ###### Objective-C
407 | ``` objective-c
408 | [UIColor colorWithComplementaryFlatColorOf:(UIColor *)someUIColor];
409 | ```
410 |
411 | ###### Swift
412 | ``` swift
413 | UIColor(complementaryFlatColorOf:someUIColor)
414 | ```
415 |
416 | ##### Chameleon Shorthand:
417 | ###### Objective-C
418 | ``` objective-c
419 | ComplementaryFlatColorOf(color);
420 | ```
421 |
422 | ###### Swift
423 | ``` swift
424 | ComplementaryFlatColorOf(color)
425 | ```
426 |
427 | #### Contrasting Colors
428 | The contrasting color feature returns either a dark color a light color depending on what the Chameleon algorithm believes is a better choice. You can specify whether the dark or light colors are flat: *`([UIColor flatWhiteColor]` & `[UIColor flatBlackColorDark]`)* or non-flat *(`[UIColor whiteColor]` & `[UIColor blackColor]`).*
429 |
430 | If you're trying to set a `UILabel's textColor` property, make sure you provide the `UILabel's backgroundColor`. If your label has a clear `backgroundColor`, just provide the `backgroundColor` property of the object directly behind the `UILabel`.
431 |
432 | Here's an example:
433 |
434 | ##### Normal Convention:
435 | ###### Objective-C
436 | ``` objective-c
437 | [UIColor colorWithContrastingBlackOrWhiteColorOn:(UIColor *)backgroundColor isFlat:(BOOL)flat];
438 | ```
439 |
440 | ###### Swift
441 | ``` swift
442 | UIColor(contrastingBlackOrWhiteColorOn:UIColor!, isFlat:Bool)
443 | ```
444 |
445 | ##### Chameleon Shorthand:
446 | ###### Objective-C
447 | ``` objective-c
448 | ContrastColor(backgroundColor, isFlat);
449 | ```
450 |
451 | ###### Swift
452 | ``` swift
453 | ContrastColor(backgroundColor, isFlat)
454 | ```
455 |
456 | #### Flattening Non-Flat Colors
457 | As mentioned previously, this feature is unique to Chameleon. While this feature is in its early stages of operation and can be improved, it is accurate in finding the nearest flat version of any color in the spectrum, and very simple to use:
458 |
459 | ##### Normal Convention:
460 | ###### Objective-C
461 | ``` objective-c
462 | [(UIColor *)color flatten];
463 | ```
464 |
465 | ###### Swift
466 | ``` swift
467 | UIColor.pink.flatten()
468 | ```
469 |
470 | #### Gradient Colors
471 | Using a gradient to color an object usually requires a couple of lines of code plus many more lines to superimpose smart contrasting text. Thankfully, Chameleon takes care of that for you. We've introduced a new way to have multicolored objects, and that's with gradients!
472 |
473 | ##### Gradient Styles
474 | Chameleon provides three simple gradient styles. Gradients can be created from any number of colors you desire as long as at least two colors are provided. Don't forget that the contrasting text feature is also compatible with gradient colors!
475 |
476 | **UIGradientStyles:**
477 | * `UIGradientStyleLeftToRight` (UIGradientStyle.LeftToRight in Swift)
478 | * `UIGradientStyleTopToBottom` (UIGradientStyle.TopToBottom in Swift)
479 | * `UIGradientStyleRadial` (UIGradientStyle.Radial in Swift)
480 |
481 | ##### Normal Convention:
482 | ###### Objective-C
483 | ``` objective-c
484 | [UIColor colorWithGradientStyle:(UIGradientStyle)gradientStyle withFrame:(CGRect)frame andColors:(NSArray *)colors];
485 | ```
486 |
487 | ###### Swift
488 | ``` swift
489 | UIColor(gradientStyle:UIGradientStyle, withFrame:CGRect, andColors:[UIColor])
490 | ```
491 |
492 | ##### Chameleon Shorthand:
493 | ###### Objective-C
494 | ``` objective-c
495 | GradientColor(gradientStyle, frame, colors);
496 | ```
497 |
498 | ###### Swift
499 | ``` swift
500 | GradientColor(gradientStyle, frame, colors)
501 | ```
502 |
503 | **Objective-C Note**: If you use the Chameleon Shorthand, and use the `NSArray` literal ```@[]``` to set the array of colors, make sure you add parenthesis around it, or else you'll get an error.
504 |
505 | Note: `UIGradientStyleRadial` only uses a maximum of 2 colors at the moment. So if more colors are provided, they will not show.
506 |
507 | #### Hex Colors
508 |
509 | One of the most requested features, *hex colors*, is now available. You can simply provide a hex string with or without a *#* sign:
510 |
511 | ##### Normal Convention:
512 | ###### Objective-C
513 | ``` objective-c
514 | [UIColor colorWithHexString:(NSString *)string];
515 | ```
516 |
517 | ###### Swift
518 | ``` swift
519 | UIColor(hexString:string)
520 | ```
521 |
522 | ##### Chameleon Shorthand:
523 | ###### Objective-C
524 | ``` objective-c
525 | HexColor(hexString)
526 | ```
527 |
528 | ###### Swift
529 | ``` swift
530 | HexColor(hexString)
531 | ```
532 | #### Hex Values 
533 |
534 | Retrieving the `hexValue` of a UIColor is just as easy.
535 |
536 | ###### Objective-C
537 | ``` objective-c
538 | [FlatGreen hexValue]; //Returns @"2ecc71"
539 | ```
540 |
541 | ###### Swift
542 | ``` swift
543 | FlatGreen.hexValue //Returns @"2ecc71"
544 | ```
545 |
546 | #### Lighter and Darker Colors
547 |
548 | Sometimes all you need is a color a shade lighter or a shade darker. Well for those rare, but crucial moments, Chameleon's got you covered. You can now lighten any color the following way:
549 |
550 | ##### Normal Convention:
551 | ###### Objective-C
552 | ``` objective-c
553 | [color lightenByPercentage:(CGFloat)percentage];
554 | ```
555 |
556 | ###### Swift
557 | ``` swift
558 | color.lightenByPercentage(percentage: CGFloat)
559 | ```
560 |
561 | You can also generate a darker version of a color:
562 |
563 | ##### Normal Convention:
564 | ###### Objective-C
565 | ``` objective-c
566 | [color darkenByPercentage:(CGFloat)percentage];
567 | ```
568 |
569 | ###### Swift
570 | ``` swift
571 | color.darkenByPercentage(percentage: CGFloat)
572 | ```
573 |
574 | ### Colors From Images
575 |
576 | Chameleon now supports the extraction of colors from images. You can either generate both flat and non-flat color schemes from an image, or easily extract the average color.
577 |
578 | To generate a color scheme simply do the following:
579 | ##### Normal Convention:
580 | ###### Objective-C
581 | ``` objective-c
582 | [NSArray arrayOfColorsFromImage:(UIImage *)image withFlatScheme:(BOOL)flatScheme];
583 | ```
584 |
585 | ###### Swift (**Array extension missing**)
586 | ``` swift
587 | NSArray(ofColorsFromImage: UIImage, withFlatScheme: Bool)
588 | ```
589 |
590 | ##### Chameleon Shorthand:
591 | ###### Objective-C
592 | ``` objective-c
593 | ColorsFromImage(image, isFlatScheme)
594 | ```
595 |
596 | ###### Swift
597 | ``` swift
598 | ColorsFromImage(image, isFlatScheme)
599 | ```
600 |
601 | To extract the average color from an image, you can also do:
602 | ##### Normal Convention:
603 | ###### Objective-C
604 | ``` objective-c
605 | [UIColor colorWithAverageColorFromImage:(UIImage *)image];
606 | ```
607 |
608 | ###### Swift
609 | ``` swift
610 | UIColor(averageColorFromImage: UIImage)
611 | ```
612 |
613 | ##### Chameleon Shorthand:
614 | ###### Objective-C
615 | ``` objective-c
616 | AverageColorFromImage(image)
617 | ```
618 |
619 | ###### Swift
620 | ``` swift
621 | AverageColorFromImage(image)
622 | ```
623 |
624 | ### UIStatusBarStyle Methods
625 | #### Contrasting UIStatusBarStyle
626 | Many apps on the market, even the most popular ones, overlook this aspect of a beautiful app: the status bar style. Chameleon has done something no other framework has... it has created a new status bar style: `UIStatusBarStyleContrast`. Whether you have a `ViewController` embedded in a `NavigationController`, or not, you can do the following:
627 |
628 | ##### Normal Convention:
629 | ###### Objective-C
630 | ``` objective-c
631 | [self setStatusBarStyle:UIStatusBarStyleContrast];
632 | ```
633 |
634 | ###### Swift
635 | ``` swift
636 | self.setStatusBarStyle(UIStatusBarStyleContrast)
637 | ```
638 | ###### **Note**: Make sure that the key *View controller-based status bar appearance* in **Info.plist** is set to `YES`.
639 |
640 | ### Color Schemes Methods
641 | ###### **Note**: *Due to the limited number of flat colors currently available, color schemes may return results that reuse certain flat colors. Because of this redundancy, we have provided an option to return either a flat color scheme or a non-flat color scheme until more flat colors are added to the inventory.*
642 |
643 | The initial color can be either a non-flat color or flat color. Chameleon will return an `NSArray` of 5 `UIColors` in which the original color will be the third object of the scheme. This allows for Chameleon to designate the colors of the color scheme (2 colors counter-clockwise and 2 clockwise from the initial color), and thus, the chosen colors are aligned specifically in that order.
644 |
645 | #### Analogous Color Scheme
646 | An analogous color scheme uses three adjacent colors on the color wheel. According to Wikipedia, it’s best used with either warm or cool colors, creating a cohesive collection with certain temperature qualities as well as proper color harmony; however, this particular scheme lacks contrast and is less vibrant than complementary schemes. Within the scheme, choose one color to dominate and two to support. The remaining two colors should be used (along with black, white or gray) as accents.
647 |
648 | #### Complementary Color Scheme
649 | A complementary color scheme uses opposite colors on the color wheel. To put into slightly more technical terms, they are two colors that, when combined, produce a neutral color. Complementary colors are tricky to use extensively, but work well when you want a point of emphasis. Complementary colors are generally not favorable to use for text.
650 |
651 | #### Triadic Color Scheme
652 | A triadic scheme uses evenly spaced colors on the color wheel. The colors tend to be richly vivid and offer a higher degree of contrast while, at the same time, retain color harmony. Let one color dominate and use the two others for accent.
653 |
654 | #### Getting Colors in a Color Scheme
655 | To retrieve an array of colors, first make sure to initialize an NSMutableArray (in case you want to use the same array to replace with different colors later):
656 |
657 | ##### Normal Convention:
658 | ###### Objective-C
659 | ``` objective-c
660 | NSMutableArray *colorArray = [NSMutableArray alloc] initWithArray:[NSArray arrayOfColorsWithColorScheme:(ColorScheme)colorScheme
661 | with:(UIColor *)color
662 | flatScheme:(BOOL)isFlatScheme]];
663 | ```
664 |
665 | ###### Swift
666 | ``` swift
667 | var colorArray = NSArray(ofColorsWithColorScheme:ColorScheme, with:UIColor!, flatScheme:Bool)
668 | ```
669 |
670 | ##### Chameleon Shorthand:
671 | ###### Objective-C
672 | ``` objective-c
673 | NSMutableArray *colorArray = [[NSMutableArray alloc] initWithArray:ColorScheme(colorSchemeType, color, isFlatScheme)];
674 | ```
675 |
676 | ###### Swift
677 | ``` swift
678 | var colorArray = ColorSchemeOf(colorSchemeType, color, isFlatScheme)
679 | ```
680 |
681 | ##### Example:
682 | Assuming you want to generate an analogous color scheme for the light shade of Flat Red, perform the following method call:
683 |
684 | ##### Normal Convention:
685 | ###### Objective-C
686 | ``` objective-c
687 | NSMutableArray *colorArray = [NSMutableArray alloc] initWithArray:[NSArray arrayOfColorsWithColorScheme:ColorSchemeAnalogous
688 | with:[UIColor flatRedColor]
689 | flatScheme:YES]];
690 | ```
691 |
692 | ###### Swift
693 | ``` swift
694 | var colorArray = NSArray(ofColorsWithColorScheme:ColorScheme.Analogous, with:UIColor.flatRed, flatScheme:true)
695 | ```
696 |
697 | ##### Chameleon Shorthand:
698 | ###### Objective-C
699 | ``` objective-c
700 | NSMutableArray *colorArray = [[NSMutableArray alloc] initWithArray:ColorScheme(ColorSchemeAnalogous, FlatRed, YES)];
701 | ```
702 |
703 | ###### Swift
704 | ``` swift
705 | var colorArray = ColorSchemeOf(ColorScheme.Analogous, FlatRed(), true)
706 | ```
707 |
708 | You can then retrieve each individual color the same way you would normally retrieve any object from an array:
709 |
710 | ###### Objective-C
711 | ```objective-c
712 | UIColor *firstColor = colorArray[0];
713 | ```
714 |
715 | ###### Swift
716 | ``` swift
717 | var firstColor = colorArray[0] as! UIColor
718 | ```
719 |
720 | ### Theme Methods
721 |
722 | With Chameleon, you can now specify a global color theme with simply one line of code (It even takes care of dealing with the status bar style as well)! Here's one of three methods to get you started. `ContentStyle` allows you to decide whether text and a few other elements should be white, black, or whichever contrasts more over any UI element's `backgroundColor`.
723 |
724 | To set a global theme, you can do the following in your app delegate:
725 |
726 | ##### Normal Convention:
727 | ###### Objective-C
728 | ``` objective-c
729 | [Chameleon setGlobalThemeUsingPrimaryColor:(UIColor *)color withContentStyle:(UIContentStyle)contentStyle];
730 | ```
731 |
732 | But what if you want a different theme for a specific `UIViewController?` No problem, Chameleon allows you to override the global theme in any `UIViewController` and `UINavigationController`, by simply doing the following:
733 |
734 | ##### Normal Convention:
735 | ###### Objective-C
736 | ```objective-c
737 | //This would go in the controller you specifically want to theme differently
738 | [self setThemeUsingPrimaryColor:FlatMint withSecondaryColor:FlatBlue andContentStyle:UIContentStyleContrast];
739 | ```
740 |
741 | ###### **Note:** In order for the status bar style to automatically be set using a theme, you need to make sure that the *View controller-based status bar appearance* key in **Info.plist** is set to `NO`.
742 |
743 | #### Navigation Bar Hairline
744 |
745 | 
746 |
747 | As of `2.0.3` the navigation bar hairline view is no longer hidden by default. However, if you're seeking a true flat look (like the image above), you can hide the hairline at the bottom of the navigation bar by doing the following:
748 |
749 | ###### Objective-C
750 | ```objective-c
751 | [self.navigationController setHidesNavigationBarHairline:YES];
752 |
753 | //or
754 |
755 | self.navigationController.hidesNavigationBarHairline = YES;
756 | ```
757 |
758 | ###### Swift
759 | ```swift
760 | self.navigationController?.hidesNavigationBarHairline = true
761 | ```
762 |
763 | ## 👑 Author
764 | Chameleon was developed by **Vicc Alexander** [(@ViccsMind)](https://twitter.com/viccsmind) in 2014 using Objective-C. In 2015, full Swift support was implemented by [@Bre7](https://github.com/bre7). Currently, it is being maintained by both [@ViccAlexander](https://github.com/ViccAlexander) and [@Bre7](https://github.com/bre7).
765 |
766 | ## 📝 To Do List
767 | * ~~CocoaPods Support~~ 
768 | * ~~Table of Contents~~ 
769 | * ~~Storyboard Color Picker Add-On~~ 
770 | * ~~Xcode In-App Documentation~~ 
771 | * ~~Switch from RGB values over to HSB and LAB~~ 
772 | * ~~Gradient Colors~~ 
773 | * ~~Update GradientStyle & ShadeStyle Syntax~~ 
774 | * ~~Add Radial Gradient Support~~ 
775 | * ~~Fix Swift Conflict with `initWithArray:for:flatScheme:` method~~ 
776 | * ~~Swift Support~~ 
777 | * ~~Color Scheme From Images~~ 
778 | * ~~UIAppearance Convenience Methods~~ 
779 | * ~~Add option to hide `NavigationBar` hairline~~ 
780 | * ~~Add support for App Extensions hairline~~ 
781 | * Add Swift Support for Random Colors
782 | * Allow Gradient Colors to Adapt To Frame Changes
783 |
784 | ## 📄 Change Log
785 |
786 | ### See [Changelog.md](https://github.com/ViccAlexander/Chameleon/blob/master/CHANGELOG.md) 👀
787 |
788 |
--------------------------------------------------------------------------------