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

后端 未结 15 1132
一整个雨季
一整个雨季 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:34

    Get the color automatically by using this code:

    static let DefaultButtonColor = UIButton(type: UIButtonType.System).titleColorForState(.Normal)!
    
    0 讨论(0)
  • 2020-12-22 16:34

    The UIWindow.tintColor method wasn't working for me in iOS8 (it was still black), so I had to do this:

    let b = UIButton.buttonWithType(UIButtonType.System) as UIButton
    var color = b.titleColorForState(.Normal)
    

    This gave the proper blue tint seen in a UIBarButtonItem

    0 讨论(0)
  • 2020-12-22 16:35

    Use self.view.tintColor from a view controller, or self.tintColor from a UIView subclass.

    0 讨论(0)
  • 2020-12-22 16:36

    Hex Color code

    #007AFF
    

    and you need this libary https://github.com/thii/SwiftHEXColors

    ps. iOS, Swift

    0 讨论(0)
  • 2020-12-22 16:36

    Please don't mess with view.tintColor or extensions, but simply use this:

    UIColor.systemBlue
    
    0 讨论(0)
  • 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
    
    0 讨论(0)
提交回复
热议问题