Can't change UINavigationBar prompt color

前端 未结 9 1508
-上瘾入骨i
-上瘾入骨i 2021-01-04 01:57

I am unable to change the prompt color on my navigation bar. I\'ve tried the code below in viewDidLoad, but nothing happens.

self.navigationCont         


        
9条回答
  •  -上瘾入骨i
    2021-01-04 02:28

    You can try this:

    import UIKit
    class ViewController: UITableViewController {
        override func viewWillAppear(_ animated: Bool) {
            super.viewWillAppear(animated)
            updatePrompt()
        }
        override func viewDidAppear(_ animated: Bool) {
            super.viewDidAppear(animated)
            updatePrompt()
        }
        func updatePrompt() {
            navigationItem.prompt = " "
            for view in navigationController?.navigationBar.subviews ?? [] where NSStringFromClass(view.classForCoder) == "_UINavigationBarModernPromptView" {
                if let prompt = view.subviews.first as? UILabel {
                    prompt.text = "Hello Red Prompt"
                    prompt.textColor = .red
                }
            }
            navigationItem.title = "This is the title (Another color)"
        }
    }
    

提交回复
热议问题