mirror of
https://github.com/morgan9e/macos-stats
synced 2026-04-14 00:04:15 +09:00
feat: moved from the HEX colors to the RGB
This commit is contained in:
@@ -469,24 +469,6 @@ extension URL {
|
||||
}
|
||||
|
||||
public extension NSColor {
|
||||
convenience init(hexString: String, alpha: CGFloat = 1.0) {
|
||||
let hexString: String = hexString.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines)
|
||||
let scanner = Scanner(string: hexString)
|
||||
if hexString.hasPrefix("#") {
|
||||
scanner.scanLocation = 1
|
||||
}
|
||||
var color: UInt32 = 0
|
||||
scanner.scanHexInt32(&color)
|
||||
let mask = 0x000000FF
|
||||
let r = Int(color >> 16) & mask
|
||||
let g = Int(color >> 8) & mask
|
||||
let b = Int(color) & mask
|
||||
let red = CGFloat(r) / 255.0
|
||||
let green = CGFloat(g) / 255.0
|
||||
let blue = CGFloat(b) / 255.0
|
||||
self.init(red: red, green: green, blue: blue, alpha: alpha)
|
||||
}
|
||||
|
||||
func grayscaled() -> NSColor {
|
||||
guard let space = CGColorSpace(name: CGColorSpace.extendedGray),
|
||||
let cg = self.cgColor.converted(to: space, intent: .perceptual, options: nil),
|
||||
|
||||
Reference in New Issue
Block a user