gpt4 book ai didi

ios - 如何更改导航栏标题的颜色?

转载 作者:搜寻专家 更新时间:2023-11-01 06:00:46 24 4
gpt4 key购买 nike

我有一个简单的导航栏和通过 Storyboard设置的标题。我为标题设置了白色。

enter image description here

然后我增加了尺寸。

navigationController?.navigationBar.prefersLargeTitles = true

enter image description here

这会自动更改我标题的颜色/字体和所有属性。

我已经尝试了几种方法(因为我们通常会更改所有属性),但在我增加尺寸后,它们似乎都不起作用。

在这种情况下如何自定义标题?

注意*:我询问的是特定 NavVC/VC 标题的颜色。不在所有 VC 的 AppDelegate 中。

回答:请遵循: Changing the text color of a navigation bar title when "prefersLargeTitles" is set to true

最佳答案

使用下面的代码改变颜色

UINavigationBar.appearance().titleTextAttributes = [NSAttributedStringKey(rawValue: NSAttributedStringKey.foregroundColor.rawValue): UIColor.orange]

如果另一个不起作用,请这样尝试;

if #available(iOS 11.0, *) {
//To change iOS 11 navigationBar largeTitle color

UINavigationBar.appearance().prefersLargeTitles = true
UINavigationBar.appearance().largeTitleTextAttributes = [NSAttributedStringKey(rawValue: NSAttributedStringKey.foregroundColor.rawValue): UIColor.white]

} else {
// for default navigation bar title color
UINavigationBar.appearance().titleTextAttributes = [NSAttributedStringKey(rawValue: NSAttributedStringKey.foregroundColor.rawValue): UIColor.white]

}

关于ios - 如何更改导航栏标题的颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51658425/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com