I am trying to see if I can make the color of the bottom tabview change depending on which tab item is selected. Currently I can make the tabview bar clear with the below code in the init.
let tabBar = UITabBar.appearance()
init() {
tabBar.barTintColor = UIColor.clear
tabBar.backgroundImage = UIImage()
tabBar.shadowImage = UIImage()
}
...
TabView(selection: $selectedTab) {
FirstView()
.tabItem{
Text("First")
}
SecondView()
.tabItem{
Text("Second")
}
}
.onAppear{
setTabViewBackground()
}
func setTabViewBackground() {
if selectedTab != 0 {
tabBar.barTintColor = UIColor.blue
}
}
Tried to just fire the func when the body redraws and idk if its this declarative style that's getting the best of me but doesn't change the tabview background at all.