I'm trying to implement a tab bar on iOS 26 like the Music or Health apps on iPhone.
On a white background this is not noticeable, but when changing the background color to dark at the start of the application, as well as when selecting a tab with a scroll view (Home tab), I observe a change in the background of the tab bar to white (sometimes the color returns to dark, and sometimes remains white). If you switch between tabs without scroll view (Account, Settings, Favorites), this behavior is not observed.
I have tabBar view:
struct MainTabView: View {
@State var selection: Int = 0
var body: some View {
TabView(selection: self.$selection) {
Tab("Account", systemImage: "person.crop.circle", value: 0) {
AccountView()
}
Tab("Settings", systemImage: "gear", value: 1) {
Text("Settings")
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(.black)
.foregroundStyle(.white)
}
Tab("Home", systemImage: "house", value: 2) {
HomeView()
}
Tab("Favorites", systemImage: "star", value: 3) {
Text("Favorites")
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(.black)
.foregroundStyle(.white)
}
}
.tint(.red)
.onAppear {
let appearance = UITabBarAppearance()
appearance.configureWithOpaqueBackground()
appearance.backgroundColor = UIColor.black
UITabBar.appearance().standardAppearance = appearance
UITabBar.appearance().scrollEdgeAppearance = appearance
UINavigationBar.appearance().largeTitleTextAttributes = [.foregroundColor: UIColor.white]
}
}
}
view with ScrollView on which the behavior is reproduced:
struct HomeView: View {
var body: some View {
ScrollView {
Text("Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of de Finibus Bonorum et Malorum (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. \nThe first line of Lorem Ipsum, Lorem ipsum dolor sit amet.., comes from a line in section 1.10.32. \nThe standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from de Finibus Bonorum et Malorum by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.\n")
.foregroundStyle(.white)
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(.black)
}
}
TabBar creates in sceneDelegate:
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let windowScene = (scene as? UIWindowScene) else { return }
let hc = UIHostingController(rootView: MainTabView())
hc.view.backgroundColor = .black
self.window = UIWindow(windowScene: windowScene)
self.window?.rootViewController = hc
self.window?.makeKeyAndVisible()
}
In AccountView I am trying to set the background of the toolbar but it didn't work:
struct AccountView: View {
var body: some View {
NavigationStack {
Text("Account")
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(.black)
.foregroundStyle(.white)
.navigationTitle("Account")
}
.toolbarBackground(.black, for: .tabBar)
.toolbarBackgroundVisibility(.visible, for: .tabBar)
}
}
In summary: I tried changing the backgroundColor of all possible views, binding the color via UITabBarAppearance, and also using the toolbarBackground modifier and none of this helped solve the bug.
I thought it was just an Apple bug, but since it doesn't exist in native apps, I must have missed something. Maybe someone can point me to something wrong. Thanks.