0

So as of now, I just have the default MKMapView pin working. But I want a custom image to replace that little red pin. This is what I have below. What am I missing? I figured defining the view.image would do the trick, but I guess not.

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:   
  (id<MKAnnotation>)annotation {
    MKPinAnnotationView *view = [[MKPinAnnotationView alloc]  
    initWithAnnotation:annotation reuseIdentifier:@"pin"];
    view.enabled = YES;
    view.animatesDrop = YES;
    view.canShowCallout = YES;
    view.image = [UIImage imageNamed:@"custom-pin-image.png"];

    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage         
     imageNamed:@"custom-image-for-annotation.png"]];
    view.leftCalloutAccessoryView = imageView;
    view.rightCalloutAccessoryView = [UIButton buttonWithType:  
     UIButtonTypeDetailDisclosure];

    return view;
}
jcaron
  • 17,302
  • 6
  • 32
  • 46
Michael Sebastian
  • 785
  • 3
  • 15
  • 33

1 Answers1

6

MKPinAnnotationView is a subclass of MKAnnotationView, it has the image property but it ignores it an displays the default pin image instead.

You should use the MKAnnotationView instead.

Also, make sure that your MKMapView delegate hasn't been nilled.

Ivan Le Hjelmeland
  • 1,065
  • 11
  • 26
  • Tat did the trick. Thanks. Is there a way to keep the "animateDrop" through for the custom image or no? – Michael Sebastian Jan 15 '16 at 15:57
  • @MichaelSebastian Oh, I forgot to mention that you loose the animateDrop-function by going for the MKAnnoationView. Check out this answer for a solution with a custom MKAnnotationView: http://stackoverflow.com/a/24060673/3655491 – Ivan Le Hjelmeland Jan 15 '16 at 16:07