【问题标题】:Cannot set custom large title in NavigationBar无法在 NavigationBar 中设置自定义大标题
【发布时间】:2020-05-07 20:21:34
【问题描述】:

似乎我只能在不使用字体时更改大标题。使用自定义字体时无法更改标题属性。

  navigationItem.title = “title”

使用自定义字体代替系统字体时如何更改大标题?

【问题讨论】:

  • stackoverflow.com/a/61644055/1780632 请检查我的答案...希望它会有所帮助
  • 我不想在我的 NavigationBar 中添加标签
  • navigationController?.navigationBar.prefersLargeTitles = true 那么这有意义吗?
  • 如前所述,我可以设置一个大标题,但不能使用自定义字体更改它。 PrefersLargeTitles 当然已经是真的了。
  • 你到底想做什么?您是在询问大标题和普通标题的单独标题吗?

标签: swift uinavigationbar swift5


【解决方案1】:

在您的控制器的 viewDidLoad 中,只需将此代码与您的特定字体和颜色值一起放入。它将显示具有相应标题属性的普通和大标题。

navigationItem.largeTitleDisplayMode = .always
navigationItem.title = "Your Title"

navigationController?.navigationBar.titleTextAttributes = [
    NSAttributedString.Key.font: Font.medium(15),
    NSAttributedString.Key.foregroundColor: Color.black
]

navigationController?.navigationBar.largeTitleTextAttributes = [
    NSAttributedString.Key.font: Font.medium(25),
    NSAttributedString.Key.foregroundColor: Color.black
]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-26
    • 2015-03-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多