Skip to content

Instantly share code, notes, and snippets.

@Aakashcs
Created July 16, 2020 00:23
Show Gist options
  • Save Aakashcs/e212103328225b09f1f37b0e46ace9d1 to your computer and use it in GitHub Desktop.
Save Aakashcs/e212103328225b09f1f37b0e46ace9d1 to your computer and use it in GitHub Desktop.
SwiftUI Color from Hex
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