I added 5 tab items in TabView. The middle one is an Image view, while the others are Text views. Why are they not vertically centered? The Image view floats on top of the TabView.
This is the code,
struct ContentView: View {
var body: some View {
TabView {
Text("")
.tabItem {
Text("One")
}
Text("")
.tabItem {
Text("Two")
}
Text("")
.tabItem {
Image(systemName: "plus.app")
}
Text("")
.tabItem {
Text("Three")
}
Text("")
.tabItem {
Text("Four")
}
}
.onAppear {
let tabBarItemAppearence = UITabBarItemAppearance()
let tabBarAppearance = UITabBarAppearance()
tabBarAppearance.shadowColor = UIColor(.gray)
tabBarAppearance.stackedLayoutAppearance = tabBarItemAppearence
UITabBar.appearance().scrollEdgeAppearance = tabBarAppearance
}
}
}
#Preview {
ContentView()
}
After replacing the Text view with the Label view that sets the systemImage property, it appears that the image in the Label view aligns with the Image view.
Are there ways to vertically center general views within tabItems?






Actually, you can't, TabBar item contains an image and text by default. It was designed for this alignment. You need to customize a View yourself, something like:
However, there are many drawbacks, such as: handling action gesture, safeArea padding, etc. You must cover it by yourself.