SwiftUI中watchOS的NavigationBarTitle颜色更改

问题描述 投票:3回答:2

enter image description here

在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))

    }

}
xcode swiftui navigationbar watchos-6
2个回答
4
投票

此时,要更改NavigationBarTitle的颜色,它们在SwiftUI中不是直接的api。但是你可以这样改变它1)转到Interface.storyboard中的AppName WatchKit App文件。2)选择Hosting Controller Scene,转到File Inspector并将Global Tint更改为您的自定义颜色。


1
投票

用于更改文本颜色的修饰符是.foregroundColor(),因此您应该编写:

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

强调色是UIKit中称为色调的颜色,即可点击项的颜色。 ForegroundColor用于不可点击的项目,使它们具有某种颜色。

© www.soinside.com 2019 - 2024. All rights reserved.