views:

89

answers:

1

I have a MKMapView in my app with several pins on it and I'd like to set different colors for each pin. My view controller is implementing MKMapViewDelegate and I've defined viewForAnnotation method.

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

It works fine and changes pin color to green. However the color is changed for all pins and I'd like to color them with several colors (based on some criteria I'd define, lets assume I want to have odd pins green and even pins yellow or something as simple as that). How can this be achieved?

A: 

-
if(annotation.fillsYourCriteria)
annView.pinColor = MKPinAnnotationColorGreen;
else
annView.pinColor = MKPinAnnotationColorYellow;
return annView;

Something as simple as that?

Gubb
Not really. API provides only three pin colors, what I want to get is have more of them.
RaYell