Created
October 16, 2017 18:47
-
-
Save reejosamuel/2ab22f6a8e0b899e31c4db4ee2392af1 to your computer and use it in GitHub Desktop.
UIColor extensions for hex color
This file contains hidden or 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
extension UIColor { | |
public convenience init(hex: UInt32) { | |
let mask = 0x000000FF | |
let r = Int(hex >> 16) & mask | |
let g = Int(hex >> 8) & mask | |
let b = Int(hex) & mask | |
let red = CGFloat(r) / 255 | |
let green = CGFloat(g) / 255 | |
let blue = CGFloat(b) / 255 | |
self.init(red:red, green:green, blue:blue, alpha:1) | |
} | |
public class var background: UIColor { return UIColor(hex: 0x000000) } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment