Skip to content

Instantly share code, notes, and snippets.

@kuotinyen
Last active December 21, 2018 09:50
Show Gist options
  • Save kuotinyen/d5f19ed23c5b3d82bb1f74ac9f7af3c4 to your computer and use it in GitHub Desktop.
Save kuotinyen/d5f19ed23c5b3d82bb1f74ac9f7af3c4 to your computer and use it in GitHub Desktop.
Add UIColor hex-init way.

Usage

static var color = UIColor(rgb: 0x2e3550)

Extension

extension UIColor {
    convenience init(rgb: UInt) {
        self.init(
            red: CGFloat((rgb & 0xFF0000) >> 16) / 255.0,
            green: CGFloat((rgb & 0x00FF00) >> 8) / 255.0,
            blue: CGFloat(rgb & 0x0000FF) / 255.0,
            alpha: CGFloat(1.0)
        )
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment