NavigationBarTitle color change for watchOS in SwiftUI

时光怂恿深爱的人放手 提交于 2020-01-13 18:30:14

问题


In the image above id like to change -02:49 to a color such as Color.blue

I've tried:

struct ContentView: View {

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

    }
}

and I've also tried adding it in the actual PlayerView as follows:

struct PlayerView: View {

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

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

    }

}

I've also tried:

   struct PlayerView: View {

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

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

    }

}

回答1:


At this point for change color of navigationBarTitle their is no direct api in SwiftUI.

But you can change it like this,
1) Go to Interface.storyboard file inside your AppName WatchKit App.
2) Select Hosting Controller Scene, Go to File Inspector and change Global Tint to your Custom Color.




回答2:


The modifier to change text colour is .foregroundColor(), so you should write:

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

Accent colour is what was known in UIKit as tint colour, i.e. the colour of clickable items. ForegroundColor is used for nonclickable items to give them a certain colour.



来源:https://stackoverflow.com/questions/58035341/navigationbartitle-color-change-for-watchos-in-swiftui

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!