Skip to content

Instantly share code, notes, and snippets.

@KimDarren
Created May 6, 2017 02:25
Show Gist options
  • Save KimDarren/8360e66f3a48665150d7d9fe0168c6dd to your computer and use it in GitHub Desktop.
Save KimDarren/8360e66f3a48665150d7d9fe0168c6dd to your computer and use it in GitHub Desktop.
Convert decimal to UIColor in Swift.
// 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