Created
May 6, 2017 02:25
-
-
Save KimDarren/8360e66f3a48665150d7d9fe0168c6dd to your computer and use it in GitHub Desktop.
Convert decimal to UIColor in Swift.
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
// Usage: UIColor(decimal: -6926516) | |
import Foundation | |
extension UIColor { | |
convenience init(decimal c: Int) { | |
let red = CGFloat((c>>16) & 0xFF) / CGFloat(255) | |
let green = CGFloat((c>>8) & 0xFF) / CGFloat(255) | |
let blue = CGFloat((c>>0) & 0xFF) / CGFloat(255) | |
self.init(red: red, | |
green: green, | |
blue: blue, | |
alpha: 1.0) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment