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

前端 未结 18 2173
星月不相逢
星月不相逢 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:28

    Setting text color of navigation bar title to white in Swift version 4.2:

    navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
    
    0 讨论(0)
  • 2020-12-02 04:28

    Swift 4.1

    Add a func to viewDidLoad

    override func viewDidLoad() {
      super.viewDidLoad()
    
      setup()
    }   
    

    In the setup() function add:

    func setup() {
    
            navigationController?.navigationBar.prefersLargeTitles = true
            navigationController?.navigationBar.barStyle = .blackOpaque
            navigationItem.title = "YOUR_TITLE_HERE"
            navigationController?.navigationBar.barTintColor = .black
            let attributes = [NSAttributedStringKey.foregroundColor: UIColor.white]
            navigationController?.navigationBar.largeTitleTextAttributes = attributes
        }
    
    0 讨论(0)
  • 2020-12-02 04:31

    Updated with swift 4

    override func viewDidLoad() {
        super.viewDidLoad()
            self.navigationController?.navigationBar.tintColor = UIColor.blue
            self.navigationController?.navigationBar.barStyle = UIBarStyle.black
    }
    
    0 讨论(0)
  • 2020-12-02 04:31

    In Swift5 and Xcode 10

    self.navigationItem.title = "your name"
    let textAttributes = [NSAttributedStringKey.foregroundColor:UIColor.white]
    navigationController?.navigationBar.titleTextAttributes = textAttributes
    
    0 讨论(0)
  • 2020-12-02 04:31

    Swift 4

    override func viewDidLoad() {
        super.viewDidLoad()
    
        navigationController?.navigationBar.barTintColor = UIColor.orange
        navigationController?.navigationBar.tintColor = UIColor.white
        navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.white]
    }
    
    0 讨论(0)
  • 2020-12-02 04:35

    I like Alex's answer. If you want something quick to try out in a ViewController make sure you use

    viewWillAppear()
    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
        var nav = self.navigationController?.navigationBar
        nav?.barStyle = UIBarStyle.Black
        nav?.tintColor = UIColor.white
        nav?.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.orange]
        //nav?.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.orange] // swift 4.2
    }
    

    enter image description here

    0 讨论(0)
提交回复
热议问题