diff --git a/Chameleon.xcodeproj/project.pbxproj b/Chameleon.xcodeproj/project.pbxproj index 271dce6..31f0ead 100755 --- a/Chameleon.xcodeproj/project.pbxproj +++ b/Chameleon.xcodeproj/project.pbxproj @@ -660,6 +660,7 @@ ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -709,6 +710,7 @@ MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -734,7 +736,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -755,7 +757,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.viccalexander.Chameleon; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; }; name = Release; }; @@ -780,7 +782,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.viccalexander.ChameleonDemo-Swift"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -805,7 +807,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.viccalexander.ChameleonDemo-Swift"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; @@ -819,7 +821,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.viccalexander.ChameleonDemo; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -832,7 +834,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.viccalexander.ChameleonDemo; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; }; name = Release; }; diff --git a/ChameleonDemo-Swift/FirstViewController.swift b/ChameleonDemo-Swift/FirstViewController.swift index 01ef1aa..e573428 100644 --- a/ChameleonDemo-Swift/FirstViewController.swift +++ b/ChameleonDemo-Swift/FirstViewController.swift @@ -59,7 +59,7 @@ class FirstViewController: UITableViewController { let randomFlatColorContract = ContrastColorOf(randomFlatColor, returnFlat: true) // Nav bar navigationController?.navigationBar.barTintColor = randomFlatColor - navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: randomFlatColorContract] + navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor.rawValue: randomFlatColorContract] // Tab bar tabBarController?.tabBar.barTintColor = randomFlatColor tabBarController?.tabBar.tintColor = randomFlatColorContract diff --git a/ChameleonDemo-Swift/SecondViewController.swift b/ChameleonDemo-Swift/SecondViewController.swift index a0f1246..e786c26 100644 --- a/ChameleonDemo-Swift/SecondViewController.swift +++ b/ChameleonDemo-Swift/SecondViewController.swift @@ -42,7 +42,7 @@ class SecondViewController: UITableViewController { override func viewDidLoad() { super.viewDidLoad() - navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: tabBarController?.tabBar.tintColor ?? UIColor.gray] + navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor.rawValue: tabBarController?.tabBar.tintColor ?? UIColor.gray] navigationController?.navigationBar.barTintColor = tabBarController?.tabBar.barTintColor ?? UIColor.lightGray sampleOneImageView.image = #imageLiteral(resourceName: "SampleImageOne") sampleTwoImageView.image = #imageLiteral(resourceName: "SampleImageTwo") @@ -54,7 +54,7 @@ class SecondViewController: UITableViewController { } override func viewWillAppear(_ animated: Bool) { - navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: tabBarController?.tabBar.tintColor ?? UIColor.gray] + navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor.rawValue: tabBarController?.tabBar.tintColor ?? UIColor.gray] navigationController?.navigationBar.barTintColor = tabBarController?.tabBar.barTintColor ?? UIColor.lightGray } diff --git a/Pod/Classes/Objective-C/UIColor+Chameleon.m b/Pod/Classes/Objective-C/UIColor+Chameleon.m index 5c9ae8a..77395d8 100755 --- a/Pod/Classes/Objective-C/UIColor+Chameleon.m +++ b/Pod/Classes/Objective-C/UIColor+Chameleon.m @@ -950,7 +950,9 @@ - (void)getRGBAComponents:(CGFloat[4])rgba { rgba[3] = 1.0f; break; } - } + case kCGColorSpaceModelXYZ: + break; + } } //Check if color is in the monochrome or rgb color space diff --git a/Pod/Classes/Swift/ChameleonShorthand.swift b/Pod/Classes/Swift/ChameleonShorthand.swift index a33d633..079fc78 100755 --- a/Pod/Classes/Swift/ChameleonShorthand.swift +++ b/Pod/Classes/Swift/ChameleonShorthand.swift @@ -1,247 +1,224 @@ - -// 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. - - */ +// +// 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. +private let DEFAULT_COLOR = UIColor.white -- parameter color: The color whose complementary color is being requested. +// MARK: - UIColor Methods Shorthand -- returns: A flat UIColor object in the HSB colorspace. -*/ -public func ComplementaryFlatColorOf(_ color: UIColor) -> UIColor { +/// 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 { +/// 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 { +/// 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) +public func HexColor(hexString: String, _ alpha: CGFloat = 1.0) -> UIColor { + return UIColor(hexString: hexString, withAlpha: alpha) ?? DEFAULT_COLOR } -/** - 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) +/// 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 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] +/// 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] { + 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. -*/ +/// 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 + return UIColor.randomFlat } public func ClearColor() -> UIColor { - return UIColor.clear + return UIColor.clear } - // MARK: - Light Shades Shorthand public func FlatBlack() -> UIColor { - return UIColor.flatBlack + return UIColor.flatBlack } public func FlatBlue() -> UIColor { - return UIColor.flatBlue + return UIColor.flatBlue } public func FlatBrown() -> UIColor { - return UIColor.flatBrown + return UIColor.flatBrown } public func FlatCoffee() -> UIColor { - return UIColor.flatCoffee + return UIColor.flatCoffee } public func FlatForestGreen() -> UIColor { - return UIColor.flatForestGreen + return UIColor.flatForestGreen } public func FlatGray() -> UIColor { - return UIColor.flatGray + return UIColor.flatGray } public func FlatGreen() -> UIColor { - return UIColor.flatGreen + return UIColor.flatGreen } public func FlatLime() -> UIColor { - return UIColor.flatLime + return UIColor.flatLime } public func FlatMagenta() -> UIColor { - return UIColor.flatMagenta + return UIColor.flatMagenta } public func FlatMaroon() -> UIColor { - return UIColor.flatMaroon + return UIColor.flatMaroon } public func FlatMint() -> UIColor { - return UIColor.flatMint + return UIColor.flatMint } public func FlatNavyBlue() -> UIColor { - return UIColor.flatNavyBlue + return UIColor.flatNavyBlue } public func FlatOrange() -> UIColor { - return UIColor.flatOrange + return UIColor.flatOrange } public func FlatPink() -> UIColor { - return UIColor.flatPink + return UIColor.flatPink } public func FlatPlum() -> UIColor { - return UIColor.flatPlum + return UIColor.flatPlum } public func FlatPowderBlue() -> UIColor { - return UIColor.flatPowderBlue + return UIColor.flatPowderBlue } public func FlatPurple() -> UIColor { - return UIColor.flatPurple + return UIColor.flatPurple } public func FlatRed() -> UIColor { - return UIColor.flatRed + return UIColor.flatRed } public func FlatSand() -> UIColor { - return UIColor.flatSand + return UIColor.flatSand } public func FlatSkyBlue() -> UIColor { - return UIColor.flatSkyBlue + return UIColor.flatSkyBlue } public func FlatTeal() -> UIColor { - return UIColor.flatTeal + return UIColor.flatTeal } public func FlatWatermelon() -> UIColor { - return UIColor.flatWatermelon + return UIColor.flatWatermelon } public func FlatWhite() -> UIColor { - return UIColor.flatWhite + return UIColor.flatWhite } public func FlatYellow() -> UIColor { - return UIColor.flatYellow + return UIColor.flatYellow } // MARK: - Chameleon - Dark Shades Shorthand public func FlatBlackDark() -> UIColor { - return UIColor.flatBlackDark + return UIColor.flatBlackDark } public func FlatBlueDark() -> UIColor {