How can I get the iOS 7 default blue color programmatically?

后端 未结 15 1252
一整个雨季
一整个雨季 2020-12-22 16:04

I\'m creating custom elements in my app and want to match the look and feel of the new iOS. iOS 7 introduced to us a very common lighter blue color, the default color or tin

15条回答
  •  再見小時候
    2020-12-22 16:37

    This extension gives you native system blue color.

    extension UIColor {
    
        static var systemBlue: UIColor {
            return UIButton(type: .system).tintColor
        }
    
    }
    

    UPDATE

    Please forget what I wrote above, just figured out - there're native extension with predefined system colors we've been looking for, including system blue:

    // System colors
    
    extension UIColor {
    
    
        /* Some colors that are used by system elements and applications.
         * These return named colors whose values may vary between different contexts and releases.
         * Do not make assumptions about the color spaces or actual colors used.
         */
    
        ... 
    
        @available(iOS 7.0, *)
        open class var systemBlue: UIColor { get }
        ... 
    }
    

    You can use it directly:

    myView.tintColor = .systemBlue
    

提交回复
热议问题