Created
July 16, 2020 00:23
-
-
Save Aakashcs/e212103328225b09f1f37b0e46ace9d1 to your computer and use it in GitHub Desktop.
SwiftUI Color from Hex
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
extension Color { | |
init(hex: String) { | |
let scanner = Scanner(string: hex) | |
var rgbValue: UInt64 = 0 | |
scanner.scanHexInt64(&rgbValue) | |
let r = (rgbValue & 0xff0000) >> 16 | |
let g = (rgbValue & 0xff00) >> 8 | |
let b = rgbValue & 0xff | |
self.init(red: Double(r) / 0xff, green: Double(g) / 0xff, blue: Double(b) / 0xff) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment