Get global tint color from code

前端 未结 6 1161
眼角桃花
眼角桃花 2020-11-30 04:18

Is there a way I can get the global tint color from my project by code? To avoid a misunderstanding I mean the global tint color, which i can set in the File Inspector.

6条回答
  •  盖世英雄少女心
    2020-11-30 04:41

    Swift 4.x:

    extension UIColor {
        static var tintColor: UIColor {
            get {
                return UIApplication.shared.keyWindow?.rootViewController?.view.tintColor ?? .red
            }
        }
    }
    

    Usage:

    textField.textColor = .tintColor
    

提交回复
热议问题