ios - 导航栏标题不显示

标签 ios swift uinavigationcontroller uinavigationbar

我在 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/

相关文章:

ios - 将日期从mysql转换为NSDate

ios - 如何在 moveRowAt : sourceIndexPath:? 后删除空白部分

if-statement - 在 Swift 中的 if 语句中使用多个 let-as

ios - 将数据从 VC1 传递到 VC4

ios - UITextView 内容在 UINavigationBar 下

ios - Runner.app/Runner.app/...无限循环Xcode构建失败

ios - 文件路径为零

Swift 3.0 - TableViewCell 上每个 CellIndentationLevel 的垂直线

ios - UICollectionView 单元格个体高度

ios - UINavigtionController Nib 的顶部栏黑色不透明不在 UIViewController 上显示黑色