Changing pin color MKMapView

Alessandro picture Alessandro · Oct 12, 2012 · Viewed 19.3k times · Source

I add annotations to my map in this way:

MyAnnotation *annotationPoint2 = [[MyAnnotation alloc] init];
annotationPoint2.coordinate = anyLocation;
annotationPoint2.title = [NSString stringWithFormat:@"%@", obj];
annotationPoint2.subtitle = @"";  //or set to nil
annotationPoint2.keyValue = [NSString stringWithFormat:@"%@", key];
[mapPins addAnnotation:annotationPoint2];

The pins are all red, and I would like them all green. How can I change the color? I have tried the following, but it still gives a red mark:

annotationPoint2.pinColor = MKPinAnnotationColorGreen;

Answer

casillas picture casillas · Oct 12, 2012
- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation 
  {
    MKPinAnnotationView *annView=[[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:@"pin"];
    annView.pinColor = MKPinAnnotationColorGreen;
    return annView;
  }