开发者

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;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜