在以10.14作为macOS部署目标的项目中,尝试以下代码:
let colour = NSColor.controlAccentColor
var red: CGFloat = 0, green: CGFloat = 0, blue: CGFloat = 0, alpha: CGFloat = 0
colour.getRed(&red, green: &green, blue: &blue, alpha: &alpha)
print("RGBA = (\(red), \(green), \(blue), \(alpha))")
对getRed
的呼叫被冻结,print
永远无法得到控制。
答案 0 :(得分:0)
需要转换为RGB颜色空间:
let colour = NSColor.controlAccentColor
var red: CGFloat = 0, green: CGFloat = 0, blue: CGFloat = 0, alpha: CGFloat = 0
colour.usingColorSpace(.sRGB)!.getRed(&red, green: &green, blue: &blue, alpha: &alpha)
print("RGBA = (\(red), \(green), \(blue), \(alpha))") // Works OK