Reputation: 197
I am trying to customize the annotations on the map, and instead of pins I want the annotations to look like the current location indicator. How would I do this? Any advice would be great!
Upvotes: 1
Views: 95
Reputation: 1398
In general you can use custom annotation object which extends MKPointAnnotation. But if you just need to change pin image you can avoid subclassing and just implement this method
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
let identifier = "MyPin"
if annotation.isKindOfClass(MKUserLocation) {
return nil
}
var annotationView = mapView.dequeueReusableAnnotationViewWithIdentifier(identifier)
if let annotationView = annotationView {
annotationView.annotation = annotation
} else {
annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: identifier)
annotationView.image = UIImage(named: "myPinImage")
}
return annotationView
}
So it's enough for you to find correct image and replace pins with it. But if you want to follow possible changes of default currentLocation image you can reuse default view
let annotationView = mapView.viewForAnnotation(mapView.userLocation());
Upvotes: 1