Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Tabbed View Bar Color SwiftUI

Tags:

swiftui

Does anyone know how to change the background colour of a tabbed view bottom bar?

I have set the accent colour which changed the colour of my icons when I select each tab bar item.

I have tried setting the background to a colour but it doesn't change the back, and tried setting background to an image just to be sure but that also doesn't do anything.

Wondering if I need to specifically access the bottom bar somehow and then set a property on that?

like image 862
AngryDuck Avatar asked Jul 10 '19 11:07

AngryDuck


People also ask

How do I change the color in tabItem SwiftUI?

If you ever tried to change the colors of TabItems in your TabView , you might find that this is only possible via the TabViews accentColor modifier — which sets the color for all TabItems . If you want to have different colors for each item, set the accent color by using .

How do you change the background color on a TabBar in flutter?

To change tab bar background color in Flutter, first, create a getter to return the TabBar widget and then wrap the TabBar widget inside the PreferredSize -> Material widget. Inside the Material add the color property and set the color of your choice.


2 Answers

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:

Named Color

Setting Just barTintColor

Just Bar Tint Color

(As you can see, it is slightly faded)

Setting Just backgroundColor

Just Background Color

(This darkens the bar a little bit)

Setting barTintColor & isTranslucent to False

isTranslucent & barTintColor

This combination is what did it for me:

UITabBar.appearance().isTranslucent = false
UITabBar.appearance().barTintColor = UIColor(named: "Secondary")
like image 142
Mark Moeykens Avatar answered Oct 17 '22 01:10

Mark Moeykens


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"))
        }
    }
}
like image 34
Rubaiyat Jahan Mumu Avatar answered Oct 17 '22 03:10

Rubaiyat Jahan Mumu