SwiftUI 中 watchOS 的 NavigationBarTitle 颜色更改

NavigationBarTitle color change for watchOS in SwiftUI

上图中id想把-02:49改成颜色比如Color.blue

我试过:

struct ContentView: View {

    var body: some View {
        PlayerView().accentColor(Color.blue)

    }
}

和 我也试过将它添加到实际的 PlayerView 中,如下所示:

struct PlayerView: View {

    var body: some View {
        VStack{
            .... 

        }.navigationBarTitle(Text(“-2:49”))
         .accentColor(.blue)

    }

}

我也试过:

   struct PlayerView: View {

    var body: some View {
        VStack{
            .... 

        }.navigationBarTitle(Text(“-2:49”).foregroundColor(.blue))

    }

}

改变文字颜色的修饰符是.foregroundColor(),所以你应该这样写:

Text(“-2:49”).foregroundColor(.blue)

强调色在 UIKit 中被称为淡色,即可点击项目的颜色。 ForegroundColor 用于不可点击的项目以赋予它们特定的颜色。

此时更改导航栏标题的颜色在 SwiftUI 中不是直接的 api。

但是你可以这样改,
1) 转到 AppName WatchKit App 中的 Interface.storyboard 文件。
2) Select Hosting Controller Scene,转到 File Inspector 并将 Global Tint 更改为您的自定义颜色。

如果 WatchOS7/Xcode12 使用 SwiftUI 应用程序生命周期,您将没有故事板。

App 资产中现在有一个 AccentColor,您可以通过它来更改它。