10

在此处输入图像描述

在上图中,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))

    }

}
4

3 回答 3

12

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

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

Xcode12 强调色

于 2020-08-15T11:03:26.673 回答
11

此时要更改 navigationBarTitle 的颜色,它们在 SwiftUI 中没有直接的 api。

但是您可以像这样更改它,
1)转到Interface.storyboard您的AppName WatchKit App.
2) 选择Hosting Controller Scene,转到File Inspector并更改Global Tint为您的自定义颜色。

于 2019-09-23T15:57:12.083 回答
0

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

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

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

于 2019-09-20T23:52:49.347 回答