我正在try 使用SwiftUI从TabView创建列表.但当列表接触到选项卡栏时,选项卡栏就会变得透明.如果我使用".Frame"来限制列表的大小,这样列表就不会接触到选项卡栏,它就能正常工作.
为什么选项卡栏会变得透明? 我如何才能使选项卡栏不变得透明呢?
目标iOS为15.0,Xcode版本为13.4
以下是我的代码和图像.
struct HomeView: View {
@State private var selection = 1
init(){
UITabBar.appearance().backgroundColor = UIColor(Color("mainColor"))//UIColor.white
UITabBar.appearance().isTranslucent = false
UITabBar.appearance().unselectedItemTintColor = UIColor.white
UITabBar.appearance().isHidden = false
}
var body: some View {
VStack {
TabView (selection: $selection){
FeedView()
.tabItem {
Image(systemName : "person.2.circle")
.environment(\.symbolVariants, selection == 1 ? .fill : .none)
Text("피드")
}.tag(1)
NMapView()
.tabItem {
Image(systemName : "map.circle")
.environment(\.symbolVariants, selection == 2 ? .fill : .none)
Text("지도")
}.tag(2)
SearchView()//text: "")
.tabItem {
Image(systemName : "magnifyingglass.circle")
.environment(\.symbolVariants, selection == 3 ? .fill : .none)
Text("검색")
}.tag(3)
SettingView()
.tabItem {
Image(systemName : "ellipsis.circle")
.environment(\.symbolVariants, selection == 4 ? .fill : .none)
Text("설정")
}.tag(4)
}
.accentColor(.white)
}
//.ignoresSafeArea(edges: .top)
}
}
struct SearchView: View {
let array = [
"1", "2", "3", "4", "5",
"6", "7", "8", "9", "0", "one",
"two", "three", "four", "five", "six"
]
@State private var searchText = ""
var body: some View {
VStack {
SearchBar(text: $searchText)
.padding(EdgeInsets(top: 10, leading: 0, bottom: 10, trailing: 0))
List {
ForEach(array.filter{$0.hasPrefix(searchText)}, id:\.self) {
searchText in Text(searchText)
}
}
.listStyle(PlainListStyle())
.onTapGesture {
hideKeyboard()
}
}
}
}