我正在尝试在我的 appDelegate 中使用以下代码将标题栏文本更改为自定义淡紫色阴影
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor(red: 0.9069682956, green: 0.7839415669, blue: 0.9612388015, alpha: 1)]
return true
}
但是标题栏文本仍然显示为黑色。有没有更好的方法来改变这个?
最佳答案
可能还为时过早,请尝试在 ContentView
的 init
中添加,并添加一些大标题(SwiftUI NavigationView 的默认值),例如
struct ContentView: View {
init() {
UINavigationBar.appearance().titleTextAttributes =
[NSAttributedString.Key.foregroundColor:
UIColor(red: 0.9069682956, green: 0.7839415669, blue: 0.9612388015, alpha: 1)]
UINavigationBar.appearance().largeTitleTextAttributes =
[NSAttributedString.Key.foregroundColor:
UIColor(red: 0.9069682956, green: 0.7839415669, blue: 0.9612388015, alpha: 1)]
}
// ... other code with NavigationView here
}
使用 Xcode 12.1/iOS 14.1 进行测试
关于ios - 将导航栏标题文本更改为自定义颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64763512/