Skip to main content

Map Style Following Theme

Last updated: April 24, 2026 | 2 minutes read

This example demonstrates how to use GEMKit in a UIKit application to apply a map style that follows the device theme (light/dark mode).

Check the full implementation on GitHub.

Map Light Theme
Map Dark Theme

Applying the Style on Load and Theme Change

applyStyleForCurrentTheme() reads traitCollection.userInterfaceStyle to choose between MapStyleIdentifiers.day and .night, then applies it via applyStyle(withStyleIdentifier:smoothTransition:). It is called once in viewDidLoad and again in traitCollectionDidChange(_:) whenever the system appearance changes:

ViewController.swiftView on GitHub
override func viewDidLoad() {

super.viewDidLoad()

// ...

self.applyStyleForCurrentTheme()
}

override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {

super.traitCollectionDidChange(previousTraitCollection)

if previousTraitCollection?.userInterfaceStyle != traitCollection.userInterfaceStyle {

self.applyStyleForCurrentTheme()
}
}

// MARK: - Style

func applyStyleForCurrentTheme() {

let styleIdentifier: Int

if traitCollection.userInterfaceStyle == .dark {
styleIdentifier = MapStyleIdentifiers.night.rawValue
} else {
styleIdentifier = MapStyleIdentifiers.day.rawValue
}

self.mapViewController?.applyStyle(withStyleIdentifier: styleIdentifier, smoothTransition: false)
}