Created
December 16, 2015 10:45
-
-
Save maximbilan/221a65b10362e4fd0297 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
public extension UIColor { | |
class func StringFromUIColor(color: UIColor) -> String { | |
let components = CGColorGetComponents(color.CGColor) | |
return "[\(components[0]), \(components[1]), \(components[2]), \(components[3])]" | |
} | |
class func UIColorFromString(string: String) -> UIColor { | |
let componentsString = string.replace("[", withString: "").replace("]", withString: "") | |
let components = componentsString.componentsSeparatedByString(", ") | |
return UIColor(red: CGFloat((components[0] as NSString).floatValue), | |
green: CGFloat((components[1] as NSString).floatValue), | |
blue: CGFloat((components[2] as NSString).floatValue), | |
alpha: CGFloat((components[3] as NSString).floatValue)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment