Ios 是否将导航栏标题文本更改为自定义颜色?

Ios 是否将导航栏标题文本更改为自定义颜色?,ios,swift,swiftui,uikit,Ios,Swift,Swiftui,Uikit,我正在尝试使用appDelegate中的以下代码将标题栏文本更改为自定义淡紫色 func应用程序(application:UIApplication,didFinishLaunchingWithOptions launchOptions:[UIApplication.launchOptions键:任意])->Bool{ //应用程序启动后自定义的覆盖点。 UINavigationBar.appearance().titleTextAttributes=[NSAttributedString.Ke

我正在尝试使用appDelegate中的以下代码将标题栏文本更改为自定义淡紫色

func应用程序(application:UIApplication,didFinishLaunchingWithOptions launchOptions:[UIApplication.launchOptions键:任意])->Bool{
//应用程序启动后自定义的覆盖点。
UINavigationBar.appearance().titleTextAttributes=[NSAttributedString.Key.foregroundColor:UIColor(红色:0.9069682956,绿色:0.7839415669,蓝色:0.9612388015,alpha:1)]
返回真值
}

但是,标题栏文本仍然显示为黑色。有没有更好的方法来改变这一点?

可能还为时过早,请尝试添加
ContentView
init
,并为大标题添加一些内容(这是SwiftUI NavigationView的默认设置),如

使用Xcode 12.1/iOS 14.1进行测试

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
}