Search code examples
iosswiftuicolor

UIColor extension for .cgColor colors?


Here is my UIColor extension:

extension UIColor {   
    // custom red
    public class var customRed: UIColor {
        return UIColor(red: 244/255, green: 59/255, blue: 59/255, alpha: 1)
    }
}

How do I append cgColors to it?

UIColor.someColor.cgColor

Solution

  • Try with this

    extension CGColor{
        public class var customRed: CGColor {
            return UIColor(red: 244/255, green: 59/255, blue: 59/255, alpha: 1).cgColor
        }
    }
    

    Use it

    self.view.layer.borderColor = CGColor.customRed
    

    Hope this helps you