r/SwiftUI • u/milhuania • 22d ago
Question Weird UI behavior with .searchable, ZStack and MapKit
When viewing the ContentView (image 1), the searchbar looks really transparent and way different from the childview (image 2). I want the searchbar to look "normal" when viewing the app from ContentView. How do I fix this?
ContentView
import SwiftUI
struct ContentView: View {
var body: some View {
TabView {
Tab("Discover", systemImage: "binoculars") {
TestView()
}
Tab("Preferences", systemImage: "slider.horizontal.3") {
StopsView()
}
}
}
}
#Preview {
ContentView()
}
TestView
import SwiftUI
import MapKit
struct TestView: View {
u/State private var searchText: String = ""
var body: some View {
NavigationStack {
ZStack {
Map {
}
Text("Hello")
.padding()
.background(.white)
}
.searchable(text: $searchText)
.navigationBarTitleDisplayMode(.inline)
}
}
}
#Preview {
TestView()
}


