mirror of
https://github.com/cranci1/Sora.git
synced 2026-03-11 17:45:37 +00:00
cleanup Color extension, add init documentation
This commit is contained in:
parent
477ea9d3a6
commit
2a6fd8b84f
1 changed files with 7 additions and 4 deletions
|
|
@ -8,11 +8,14 @@
|
|||
import SwiftUI
|
||||
|
||||
extension Color {
|
||||
init(hex: String) {
|
||||
var hexSanitized = hex.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
var rgb: UInt64 = 0
|
||||
Scanner(string: hexSanitized).scanHexInt64(&rgb)
|
||||
|
||||
/// Intitialize SwiftUI Color via HEX String
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - hex: The hex color string. Dont include: "#" prefix or leading / trailing whitespaces ( " " )
|
||||
init(hex: String) {
|
||||
var rgb: UInt64 = 0
|
||||
Scanner(string: hex).scanHexInt64(&rgb)
|
||||
self.init(
|
||||
.sRGB,
|
||||
red: Double((rgb & 0xFF0000) >> 16) / 255.0,
|
||||
|
|
|
|||
Loading…
Reference in a new issue