我在 AppDelegate 中这样配置我的导航栏:
func setupNavBar() {
let barAppearance = UINavigationBar.appearance()
barAppearance.titleTextAttributes = [NSAttributedString.Key.foregroundColor: appRed]
barAppearance.setBackgroundImage(UIImage(color: .white), for: UIBarMetrics.default)
barAppearance.shadowImage = UIImage()
}
这工作正常,但是当我按如下方式设置标题时:
navigationController.navigationItem.title = "Hello"
这永远行不通,我没有看到任何标题。这与我将上面的行放在哪里无关(viewDidLoad、viewDidAppear 等)
最佳答案
尝试将 View Controller 的标题属性设置为“Hello”
self.title = "Hello"
如果可行,您可以在此处的 AWebster 答案中找到解释 Swift - Title Not Appearing for Navigation View Controller
关于ios - 导航栏标题不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56417098/