Search code examples
swiftui

Change Tabbed View Bar Color 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?


Solution

  • 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"))
            }
        }
    }