When adding a Map
using the MapKit
this changes the appearance of the TabBar appearance, specifically gives the toolbar a translucent background with a shadow; the default iOS style.
I have tried adding the following modifier to the Map
.toolbarBackground(Color("White"), for: .navigationBar)
But the navigation toolbar still has a shadow, and the TabBar has the default translucent background colour with shadow.
Root
init() {
// this is not the same as manipulating the proxy directly
let appearance = UINavigationBarAppearance()
// this overrides everything you have set up earlier.
appearance.configureWithTransparentBackground()
appearance.shadowColor = .clear
//In the following two lines you make sure that you apply the style for good
UINavigationBar.appearance().scrollEdgeAppearance = appearance
UINavigationBar.appearance().standardAppearance = appearance
UITabBar.appearance().barTintColor = UIColor.white)
UITabBar.appearance().backgroundColor = UIColor.white)
UITabBar.appearance().shadowImage = UIImage()
UITabBar.appearance().backgroundImage = UIImage()
UINavigationBar.appearance().isTranslucent = false
UIToolbar.appearance().backgroundColor = UIColor.white)
UIToolbar.appearance().isTranslucent = false
UIToolbar.appearance().setShadowImage(UIImage(), forToolbarPosition: .any)
}
struct MainView: View {
var body: some View {
TabView {
ContentView()
.tabItem {
Label("Menu", systemImage: "list.dash")
}
}
}
}
The Tabbar has a solid white colour with no shadow, as well as navigation bars.
Content View
struct ContentView: View {
var body: some View {
NavigationStack() {
NavigationLink(destination: MapView()) {
Text("Hello, World!")
}
}
.navigationTitle("Content")
}
}
MapView
struct MapView: View {
@State private var region = MKCoordinateRegion(center: CLLocationCoordinate2D(latitude: 51.507222, longitude: -0.1275), span: MKCoordinateSpan(latitudeDelta: 0.5, longitudeDelta: 0.5))
var body: some View {
Map(coordinateRegion: $region)
.mapControlVisibility(.hidden)
.allowsHitTesting(false)
.frame(maxWidth: .infinity)
.frame(height: 414)
.clipped()
}
}
I have looked through the documentation but could not find anything. https://developer.apple.com/documentation/mapkit/map