Change Tabbed View Bar Color SwiftUI
SwiftUI 1.0 - Using named colors
Combining barTintColor
and isTranslucent
For some reason I wasn't getting the full color of my named color when I used just barTintColor
or even backgroundColor
. I had to include isTranslucent
too.
Here is my named color:
Setting Just barTintColor
(As you can see, it is slightly faded)
Setting Just backgroundColor
(This darkens the bar a little bit)
Setting barTintColor
& isTranslucent
to False
This combination is what did it for me:
UITabBar.appearance().isTranslucent = false
UITabBar.appearance().barTintColor = UIColor(named: "Secondary")
Here is a solution. You can change appearance
of the UITabBar and change the TabBar.
struct TabView: View {
init() {
UITabBar.appearance().backgroundColor = UIColor.blue
}
var body: some View {
return TabbedView {
Text("This is tab 1").tag(0).tabItemLabel(Text("tab1"))
Text("This is tab 2").tag(1).tabItemLabel(Text("tab2"))
Text("This is tab 3").tag(2).tabItemLabel(Text("tab3"))
}
}
}