大家好。我正在创建一个简单的 SwiftUI 应用程序,我希望我的应用程序的 TabView 具有自定义背景而不是半透明的。
为了实现这一点,我使用UITabBar.appearance().backgroundColor = Color
and UITabBar.appearance().isTranslucent = false
,它应该完全做到这一点,是的,它使栏不是半透明的,但不是为栏提供我选择的颜色,而是在选项卡栏顶部生成一个新视图t应该在那里,显然以前不在那里。
您可以注意到出现的新视图。我想这是一个问题,isTranslucent
因为当我删除它时,新视图就消失了。
有没有办法可以更改颜色并使条不半透明并且不显示该视图?
任何帮助表示赞赏。提前致谢。
我的代码
SceneDelegate(仅变色部分)
UITabBar.appearance().isTranslucent = false
UITabBar.appearance().backgroundColor = UIColor(named: "backgroundColor")
选项卡视图
struct TabController: View {
@State private var selection = 0
var body: some View {
TabView(selection: $selection) {
HomePageView()
.tabItem {
Image(systemName: "house.fill")
.font(.title)
}
.tag(0)
Text("Second View")
.font(.title)
.tabItem {
Image(systemName: "bell.fill")
.font(.title)
}
.tag(1)
}
.edgesIgnoringSafeArea(.top)
}
}