Lukas
Lukas

Reputation: 1356

MKMapView set style to black and white

i'm trying to change the color scheme of the MKMapView to black and white. It's discussed in this topic: Black and white overlay for an MKMapView but i have no clue how to achieve this.

Can somebody help me out?

Best regards, Lukas

Upvotes: 4

Views: 4541

Answers (2)

suman cherukuri
suman cherukuri

Reputation: 49

Google SDK is an overkill. It changes the fonts and it also flickers between the colors and B/W. There is a simpler solution, Just add a layer like this:

   let darkLayer = CALayer()
        darkLayer.frame = self.view.bounds
        darkLayer.compositingFilter = "colorBlendMode"
        darkLayer.backgroundColor = UIColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 1.0).cgColor
        self.view.layer.addSublayer(darkLayer)

If you want make it a bit darker, you can add another layer:

    let darkLayer2 = CALayer()
    darkLayer2.frame = self.view.bounds
    darkLayer2.compositingFilter = "overlayBlendMode"
    darkLayer2.backgroundColor = UIColor(red: 0.0, green: 0.0, blue: 0.0, 
    alpha: 0.6).cgColor
    self.view.layer.addSublayer(darkLayer2)

You also wanna force the view to be in dark mode:

    override func viewDidLoad() {
        super.viewDidLoad()
        overrideUserInterfaceStyle = .dark
    }

Upvotes: 2

Lukas
Lukas

Reputation: 1356

The solution is pretty straightforward. By using the GoogleMaps SDK you can set a mapstyle.

One can create styles through the following two sites: https://snazzymaps.com https://mapstyle.withgoogle.com

Btw: I noticed the GoogleMaps SDK is faster, more developer friendly, and offers more features anyway, so I'd recommend it anyway.

Upvotes: 1

Related Questions