Last active
April 22, 2017 21:53
-
-
Save arkilis/fa6abfc9eb66ed5527fc3ea5bb70ffa3 to your computer and use it in GitHub Desktop.
swift_extension
This file contains 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
import Foundation | |
import UIKit | |
extension UIColor { | |
convenience init(hex: String) { | |
let scanner = Scanner(string: hex) | |
scanner.scanLocation = 0 | |
var rgbValue: UInt64 = 0 | |
scanner.scanHexInt64(&rgbValue) | |
let r = (rgbValue & 0xff0000) >> 16 | |
let g = (rgbValue & 0xff00) >> 8 | |
let b = rgbValue & 0xff | |
self.init( | |
red: CGFloat(r) / 0xff, | |
green: CGFloat(g) / 0xff, | |
blue: CGFloat(b) / 0xff, alpha: 1 | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment