summaryrefslogtreecommitdiffstats
path: root/osdep/macOS_swift_extensions.swift
diff options
context:
space:
mode:
Diffstat (limited to 'osdep/macOS_swift_extensions.swift')
-rw-r--r--osdep/macOS_swift_extensions.swift13
1 files changed, 13 insertions, 0 deletions
diff --git a/osdep/macOS_swift_extensions.swift b/osdep/macOS_swift_extensions.swift
index 14d217f589..cc7438fd8c 100644
--- a/osdep/macOS_swift_extensions.swift
+++ b/osdep/macOS_swift_extensions.swift
@@ -56,3 +56,16 @@ extension NSScreen {
}
}
}
+
+extension NSColor {
+
+ convenience init(hex: String) {
+ let int = Int(hex.dropFirst(), radix: 16)
+ let alpha = CGFloat((int! >> 24) & 0x000000FF)/255
+ let red = CGFloat((int! >> 16) & 0x000000FF)/255
+ let green = CGFloat((int! >> 8) & 0x000000FF)/255
+ let blue = CGFloat((int!) & 0x000000FF)/255
+
+ self.init(calibratedRed: red, green: green, blue: blue, alpha: alpha)
+ }
+}