swiftmapkitios13ios-darkmode

How can I turn the MKMapView for dark mode?


How can I change the map to dark mode from iOS 13?

I have opt-out from UserInterfaceStyle so system-wide colors will not apply to me, so I'll do it manually.

I've seen this video from apple WWDC2019 - Session 236, at 8:19s but that's for snapshots and I didn't get it.

Actually I was trying something like:

private var mapView: MKMapView!

override func viewDidLoad() {
    super.viewDidLoad()
    mapView.backgroundColor = .black       
}

but it doesn't change the theme or appearance or the traitCollection to dark.

Any suggestion?


Solution

  • This is what you need on the viewDidLoad

    if #available(iOS 13.0, *) {
        self.overrideUserInterfaceStyle = .dark
    }