Skip to content

Instantly share code, notes, and snippets.

@aqubi
Last active November 12, 2021 07:49
Show Gist options
  • Save aqubi/4cd0aae1a732825f6f9b3a05d374835e to your computer and use it in GitHub Desktop.
Save aqubi/4cd0aae1a732825f6f9b3a05d374835e to your computer and use it in GitHub Desktop.
func toHexString4(_ color:UIColor) -> String? {
var cgColor:CGColor = color.cgColor
if let name = cgColor.colorSpace?.name, name != CGColorSpace.sRGB {
cgColor = color.cgColor.converted(to: CGColorSpace(name: CGColorSpace.sRGB)!, intent: .defaultIntent, options: nil)!
}
let ciColor = CIColor(cgColor: cgColor)
return toHexString([ciColor.red, ciColor.green, ciColor.blue, ciColor.alpha])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment