How to do it...

To customize, let's use the demo we built in the previous section. We will see how to customize the annotation object and the annotation view:

  1. Add a new Swift source file for a new class, called CustomAnnotation.
  2. Change the CustomAnnotation class to conform to the MKAnnotation protocol. The protocol requires you to define the coordinate property so that the map view can understand the location of the annotation:
 import UIKit import MapKit class CustomAnnotation: NSObject, MKAnnotation{ var coordinate: CLLocationCoordinate2D var title: String? = "" var color: UIColor override init() { coordinate = CLLocationCoordinate2D() color = UIColor.black } init(location: CLLocationCoordinate2D) { self.coordinate = location color = ...

Get iOS Programming Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.