7.5. Displaying Pins with Different Colors on a Map View
The default color for pins dropped on a map view is red. You want to be able to display pins in different colors in addition to the default color.
Return instances of
MKPinAnnotationView to your map view through
Every annotation that is added to an instance of
MKMapView has a corresponding view that gets
displayed on the map view. These views are called annotation
views. An annotation view is an object of
MKAnnotationView, which is a
UIView. If the delegate
object of a map view implements the
mapView:viewForAnnotation: delegate method,
the delegate object will have to return instances of the
MKAnnotationView class to represent (and
optionally, customize) the annotation views to be displayed on a
To set up our program so we can customize the color (choosing from the default SDK
pin colors) of the annotation view that gets dropped on a map view to
represent the annotation, we must return an instance of the
MKPinAnnotationView class instead of an
MKAnnotationView in the
method. Bear in mind that the
MKPinAnnotationView class is a subclass of the
Get iOS 6 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.