I have a UILabel with black color;
i am writing the following code to get black color\'s components.
UIColor *aColor = [aLabel.textColor retain];
con
extension UIColor {
func toRGB() -> UIColor? {
guard let model = cgColor.colorSpace?.model else {
return nil
}
let components = cgColor.components
switch model {
case .rgb:
return UIColor(red: components?[0] ?? 0.0, green: components?[1] ?? 0.0, blue: components?[2] ?? 0.0, alpha: components?[3] ?? 0.0)
case .monochrome:
return UIColor(red: components?[0] ?? 0.0, green: components?[0] ?? 0.0, blue: components?[0] ?? 0.0, alpha: components?[1] ?? 0.0)
default:
return nil
}
}
}