How to access extension of UIColor in Swift?

后端 未结 9 1494
猫巷女王i
猫巷女王i 2020-12-10 01:15

I am very new to swift and trying to create an extension of UIColor class as

extension UIColor{

    func getCustomBlueColor() -> UIColor {
        retur         


        
9条回答
  •  遥遥无期
    2020-12-10 02:13

    With Swift 3, predefined UIColors are used accordingly:

    var myColor: UIColor = .white // or .clear or whatever
    

    Therefore, if you want something similar, such as the following...

    var myColor: UIColor = .myCustomColor
    

    ...then, you would define the extension like so:

    extension UIColor {
    
        public class var myCustomColor: UIColor {
            return UIColor(red: 248/255, green: 248/255, blue: 248/255, alpha: 1.0)
        }
    
    }
    

    In fact, Apple defines white as:

    public class var white: UIColor
    

提交回复
热议问题