Switching map styles
In this recipe, you will learn how to switch between different map styles. The project contains UISegmentedControl
with two states: light and dark. It's connected to the switchMapStyle:sender
IBAction of ViewController
. We will implement the functionality needed to switch between the light and dark styles.
How to do it…
Follow these steps:
We will continue with the project as we left it in the previous recipe. Jump over to the
ViewController.m
file.Replace the
switchMapStyle:sender
method with the following code:- (IBAction)switchMapStyle:(id)sender { if ([sender isKindOfClass:[UISegmentedControl class]]) { UISegmentedControl *segmentedControl = (UISegmentedControl *)sender; if (segmentedControl.selectedSegmentIndex == 0) { NSURL *lightStyle = [NSURL URLWithString:@"asset://styles/light-v7.json"]; [self.mapView setStyleURL:lightStyle]; } else { NSURL...