Skip to content

Instantly share code, notes, and snippets.

@SlayterDev
Created April 8, 2016 20:28
Show Gist options
  • Save SlayterDev/f81cc0a47b518c434a28213c3111b617 to your computer and use it in GitHub Desktop.
Save SlayterDev/f81cc0a47b518c434a28213c3111b617 to your computer and use it in GitHub Desktop.
import UIKit
extension UIColor {
class func colorWithHexString(string: String) -> UIColor {
let num = Int(string, radix: 16)!
let r = CGFloat(num >> 16) / 255
let g = CGFloat(((num >> 8) - (num >> 8) & 0xFF00)) / 255
let b = CGFloat(num - (num & 0xFFFF00)) / 255
return UIColor(red: r, green: g, blue: b, alpha: 1.0)
}
}
let color = UIColor.colorWithHexString("00DEAD")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment