MKMapView also offers the possibility to use custom tile overlays. Openstreetmap has a great list of tile servers you could use to get a custom map. Of course there is always the possibility to create your own tile overlay set. The process is described in the Openstreetmap wiki here.
A possible implementation in Swift could look like this:
1. Import MapKit
import MapKit
2. Add overlays to map
let overlayPath = self.mapViewModel.overlayURL
let overlay = MKTileOverlay(URLTemplate: overlayPath)
overlay.canReplaceMapContent = true
self.mapView.addOverlay(overlay)
3. Conform to MKMapViewDelegate
class ViewController: UIViewController, MKMapViewDelegate { ... }
4. Implement delegate method to use the correct renderer to display the tiles
func mapView(mapView: MKMapView, rendererForOverlay overlay: MKOverlay) -> MKOverlayRenderer {
guard let tileOverlay = overlay as? MKTileOverlay else {
return MKOverlayRenderer(overlay: overlay)
}
return MKTileOverlayRenderer(tileOverlay: tileOverlay)
}
In the above example overlayURL is taken from the tile server list found on openstreetmap: OpenstreetMap Tile Servers.
For example if you would like to use the stamen map (which has a watercolor style) your url would look like:
let overlayURL = "http://tile.stamen.com/watercolor/{z}/{x}/{y}.jpg"
If you are searching for a dark-mode map you probably go best with Carto Dark: http://a.basemaps.cartocdn.com/dark_all/${z}/${x}/${y}.png
.
See that the above URLs has no SSL support (HTTP). Therefore you will need to allow insecure HTTP requests to this specific URL by adding the App Transport Security Settings
in your Info.plist. For further information have a look at this link.