NavigationBar bar, tint, and title text color in iOS 8

前端 未结 18 2280
星月不相逢
星月不相逢 2020-12-02 04:08

The background text in the status bar is still black. How do I change the color to white?

// io8, swift, Xcode 6.0.1 
override func viewDidLoad() {
    super         


        
18条回答
  •  粉色の甜心
    2020-12-02 04:48

    To do this job in storyboard (Interface Builder Inspector)

    With help of IBDesignable, we can add more options to Interface Builder Inspector for UINavigationController and tweak them on storyboard. First, add the following code to your project.

    @IBDesignable extension UINavigationController {
        @IBInspectable var barTintColor: UIColor? {
            set {
                navigationBar.barTintColor = newValue
            }
            get {
                guard  let color = navigationBar.barTintColor else { return nil }
                return color
            }
        }
    
        @IBInspectable var tintColor: UIColor? {
            set {
                navigationBar.tintColor = newValue
            }
            get {
                guard  let color = navigationBar.tintColor else { return nil }
                return color
            }
        }
    
        @IBInspectable var titleColor: UIColor? {
            set {
                guard let color = newValue else { return }
                navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: color]
            }
            get {
                return navigationBar.titleTextAttributes?["NSForegroundColorAttributeName"] as? UIColor
            }
        }
    }
    

    Then simply set the attributes for UINavigationController on storyboard.

提交回复
热议问题