Reputation: 515
I'm having some weird glitches when trying to have a ScrollView as one of my tab-views. This is my sample code:
import SwiftUI
struct ContentView: View {
// hack to set unselected tab item color
init() {
UITabBar.appearance().unselectedItemTintColor = UIColor.black
}
var body: some View {
TabView {
// first tab - just a color
Color.red.ignoresSafeArea()
.tabItem {
Image(systemName: "star")
}
// second tab - a ScrollView
ScrollView {
// fill the ScrollView with something
Rectangle()
.fill(.white)
.frame(height: 1000)
}
.background(Color.red)
.tabItem {
Image(systemName: "flag")
}
}
.tint(.white) // selected tab item = white
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
The problem is when I switch between first and second tab, the background of the TabView changes to white when I've selected the ScrollView-tab. Then it won't change back to red when selecting the first tab. But if I select the ScrollView-tab, and scroll all the way down until the TabView-background turns red again, then going back it stays red. Am I doing something wrong in my code? Is it a bug? Any workaround?
Upvotes: 0
Views: 209