Mapkit pin color not changing

柔情痞子 提交于 2019-12-06 08:02:42

问题


I'm doing the following and always get green pins:

pin.pinColor = MKPinAnnotationColorRed;
        [self.mapView addAnnotation:pin];
        [pin release];

pin is of type "NSObject ". All pins come out as green. Should I be doing it differently?


回答1:


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


来源:https://stackoverflow.com/questions/2428479/mapkit-pin-color-not-changing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!