Mapkit contacts color does not change

I do the following and always get green contacts:

pin.pinColor = MKPinAnnotationColorRed;
        [self.mapView addAnnotation:pin];
        [pin release];

pin is of type "NSObject". All contacts come out as green. Should I do it differently?

+3
source share
1 answer

Make sure that your contact class implements the MKAnnotation protocol , and I believe that in order to get a custom pin color, you have to implement the viewForAnnotation method .

- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation
{
    MKPinAnnotationView *newAnnotation = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"redpin"];
    newAnnotation.pinColor = MKPinAnnotationColorRed;
    newAnnotation.animatesDrop = YES;
    newAnnotation.canShowCallout = YES;
    return newAnnotation;
}
+7
source

Source: https://habr.com/ru/post/1736556/