Skip to content

Instantly share code, notes, and snippets.

@maximbilan
Created December 16, 2015 10:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maximbilan/221a65b10362e4fd0297 to your computer and use it in GitHub Desktop.
Save maximbilan/221a65b10362e4fd0297 to your computer and use it in GitHub Desktop.
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