How can we use Assets Catalog Color Sets?

后端 未结 9 1543
遇见更好的自我
遇见更好的自我 2020-11-29 06:57

I usually use custom UIColors on iOS using extensions with Swift, but now with iOS 11/ Xcode 9 we can create Colors Sets. How can we use them?

Update - Tip

9条回答
  •  臣服心动
    2020-11-29 07:51

    You can use this way for simple accessing (swift 4 & swift 5)

    enum AssetsColor: String {
        case backgroundGray
        case blue
        case colorAccent
        case colorPrimary
        case darkBlue
        case yellow
    }
    
    extension UIColor {
        static func appColor(_ name: AssetsColor) -> UIColor? {
             return UIColor(named: name.rawValue)
        }
    }
    

提交回复
热议问题