Search code examples
iphonecocoa-touchmkannotationmkannotationview

issue with with MKAnnotation image property


I am implementing a MKMapView based application. In that I am using a custom image instead of displaying a pin by using MKAnnotationView.Image property. It is not working. It keeps showing the standard pin in red but not the image I am pointing too. Any ideas?

- (void)setPin:(MKPinAnnotationView *)aPin forAnnotation:(id <MKAnnotation>)anAnnotation {
    if (anAnnotation == self.userAnnotation) {

        aPin.image = [UIImage imageNamed:@"youarehere.png"];
        aPin.opaque = NO;

        aPin.pinColor = MKPinAnnotationColorRed;
    }
}

Solution

  • If you use MKPinAnnotationView like you are then you don't get to set the image only the pinColor. MKPinAnnotationView only has pinColor and animatesDrop as the properties.

    You want to use the parent class MKAnnotationView. It will let you set the image.

    Read the Class Reference for each and it will make sense. This is one of the times that Objective-C makes me crazy because when you are reading those long class names in the docs, it's easy to scan right over the "Pin" variation in the class name.