开发者

Mapkit pin color not changing

开发者 https://www.devze.com 2022-12-22 12:39 出处:网络
I\'m doing the following and always get green pins: pin.pinColor = MKPinAnnotation开发者_高级运维ColorRed;

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

精彩评论

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