From c6b1e18a68b7004c7453019cb2393b4040aed14a Mon Sep 17 00:00:00 2001 From: Reid Gravelle Date: Thu, 23 Apr 2015 10:57:10 -0400 Subject: [PATCH] Creates NSColor and UIColor depending on OS --- Rainbow-Creator.swift | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/Rainbow-Creator.swift b/Rainbow-Creator.swift index 6cb4132..1c81eb5 100644 --- a/Rainbow-Creator.swift +++ b/Rainbow-Creator.swift @@ -1,6 +1,6 @@ // -// UIColor+Creator.swift -// Rainbow Creator UIColor Extension +// Rainbow-Creator.swift +// Rainbow Creator UIColor & NSColor Extension // // Created by Reid Gravelle on 2015-03-18. // Copyright (c) 2015 Northern Realities Inc. All rights reserved. @@ -24,10 +24,18 @@ // THE SOFTWARE. // +import Foundation + +#if os(iOS) import UIKit +public typealias Color = UIColor +#else +import AppKit +public typealias Color = NSColor +#endif -extension UIColor { +extension Color { /** Returns a color object representing the color with the given RGB component values and has the specified opacity. @@ -36,7 +44,7 @@ extension UIColor { :param: blueValue The blue component of the color object, specified as a value between 0 and 255. :param: alphaValue A CGFloat between 0.0 and 1.0 representing the opacity with a default value of 1.0. - :returns: The UIColor object + :returns: The color object */ convenience init ( redValue: Int, greenValue: Int, blueValue: Int, alphaValue: CGFloat = 1.0 ) { @@ -55,7 +63,7 @@ extension UIColor { :param: hex The red, green, and blue components that compromise the color combined into a single hexidecimal number. Each component has two digits which range from 0 through to f. :param: alphaValue A CGFloat between 0.0 and 1.0 representing the opacity with a default value of 1.0. - :returns: The UIColor object + :returns: The color object */ convenience init ( hex : Int, alpha : CGFloat = 1.0 ) { @@ -74,7 +82,7 @@ extension UIColor { :param: hex The red, green, and blue components that compromise the color combined into a single hexidecimal string. Each component has two characters which range from 0 through to f. The string may be optionally prefixed with a '#' sign. :param: alphaValue A CGFloat between 0.0 and 1.0 representing the opacity with a default value of 1.0. - :returns: The UIColor object + :returns: The color object */ convenience init ( hexString : String, alpha : CGFloat = 1.0 ) {