Ios 将UIExtendedSRGBColorSpace转换为uicolor
我想将UIExtendedSRGBColorSpace转换为十六进制,如中所述。我正在从Ios 将UIExtendedSRGBColorSpace转换为uicolor,ios,swift,Ios,Swift,我想将UIExtendedSRGBColorSpace转换为十六进制,如中所述。我正在从NSAttributedString获取UIExtendedSRGBColorSpace。但是我找不到一种方法来将取自NSAttributedString的UIExtendedSRGBColorSpace转换为UIColor或任何东西。如果我想转换成UIColorUIColor(cgColor:foundColor as!cgColor),我会得到以下错误:错误:执行被中断,原因:EXC\u BAD\u访问(
NSAttributedString
获取UIExtendedSRGBColorSpace
。但是我找不到一种方法来将取自NSAttributedString
的UIExtendedSRGBColorSpace
转换为UIColor或任何东西。如果我想转换成UIColorUIColor(cgColor:foundColor as!cgColor)
,我会得到以下错误:错误:执行被中断,原因:EXC\u BAD\u访问(code=EXC\u I386\u GPFLT)。进程被留在中断的位置,请使用“thread return-x”返回到表达式求值之前的状态代码>
以下是我正在做的:
let attributedText = NSAttributedString(string: "Hello, playground", attributes: [
.foregroundColor: UIColor.red,
.backgroundColor: UIColor.green,
.ligature: 1,
.strikethroughStyle: 1,
])
let foundColor = attributedText.attribute(NSAttributedString.Key.foregroundColor, at: 0, effectiveRange: nil) // convert this to hex.
//let cols = UIColor(cgColor: foundColor as! CGColor) // extendedSRGB.cgColor //foundColor.flatmap{Int($0)}
// print(cols.extendedSRGB2sRGB)
print(foundColor) // Optional(UIExtendedSRGBColorSpace 1 0 0 1)
如何将UIExtendedSRGBColorSpace转换为uicolor,以便转换为十六进制或rgb值