4

Is it possible to change the MKAnnotation pin to a png of my own design?

enter image description here

apaderno
  • 28,547
  • 16
  • 75
  • 90
Nielsou Hacken-Bergen
  • 2,606
  • 6
  • 27
  • 37

3 Answers3

4

override this and be a delegate of MKMapViewDelegate to implement override the method.

- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation;

Create an annotation,

MKAnnotationView *annotationView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID];// get a dequeued view for the annotation like a tableview

if (annotationView == nil)
    {
        annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID] autorelease]; 
    }
    annotationView.annotation = annotation;
    annotationView.canShowCallout = YES; // show the grey popup with location etc
    UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    ///[rightButton addTarget:self action:@selector(showDetails:) forControlEvents:UIControlEventTouchUpInside];
    annotationView.rightCalloutAccessoryView = rightButton;

    annoationView.image = [UIImage imageNamed:@"random.png"];

Custom image done

akashivskyy
  • 44,342
  • 16
  • 106
  • 116
Arvin Am
  • 533
  • 4
  • 11
2

Yes, in the viewForAnnotation delegate callback you can provide whatever view you like.

Kendall Helmstetter Gelner
  • 74,769
  • 26
  • 128
  • 150
1

For custom annotation image, set the image property, as such.

UIImage *annImage = [UIImage imageNamed:@"AnnotationIcon.png"];
annView.image = annImage;

Do note that the MKPinAnnotationView animateDrop property will not work on custom images. There's a way to duplicate that animation though. See How do I animate MKAnnotationView drop?

Community
  • 1
  • 1
Gavin
  • 2,784
  • 6
  • 41
  • 78