Skip to content

Commit ecdf562

Browse files
committed
Add convenience initializer to NSColor for creating color from hex value
1 parent ea168f4 commit ecdf562

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// NSColor+Hex.swift
3+
// CodeEditTextView
4+
//
5+
// Created by Tom Ludwig on 27.11.24.
6+
//
7+
8+
import AppKit
9+
10+
extension NSColor {
11+
convenience init(hex: Int, alpha: Double = 1.0) {
12+
let red = (hex >> 16) & 0xFF
13+
let green = (hex >> 8) & 0xFF
14+
let blue = hex & 0xFF
15+
self.init(srgbRed: Double(red) / 255, green: Double(green) / 255, blue: Double(blue) / 255, alpha: alpha)
16+
}
17+
}

0 commit comments

Comments
 (0)