Mapkit pin color not changing
I'm doing the following and always get green pins:
pin.pinColor = MKPinAnnotation开发者_高级运维ColorRed;
[self.mapView addAnnotation:pin];
[pin release];
pin is of type "NSObject ". All pins come out as green. Should I be doing it differently?
Make sure your pin class implements the MKAnnotation protocol and I believe to get a non-standard pin color, you'll 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;
}
精彩评论