我有一组符合 <MKAnnotation>
的对象.
我使用 addAnnotations: 将该数组加载到我的注释中。
在方法中:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:
(id<MKAnnotation>)annotation
我让每个图钉加载一个自定义图像,使用:
annotationView.image = [UIImage imageNamed:@"purp_pin.png"];
但是,我不希望所有图钉都加载这张图片。我希望它根据符合 <MKAnnotation>
的对象的属性加载不同的自定义图像/标识符有。
我该怎么做?
最佳答案
如果您的对象中有一些符合 MKAnnotation
的自定义属性,您可以在 viewForAnnotation
中访问它以设置图像的一种方法如下:
MyAnnotationClass *myAnnot = (MyAnnotationClass *)annotation;
if (myAnnot.someProperty == 42)
annotationView.image = [UIImage imageNamed:@"purp_pin.png"];
else
annotationView.image = [UIImage imageNamed:@"default.png"];
无论注释 View 是出列还是创建,请确保设置了 image
属性。
关于iphone - 如何根据属性值加载不同的自定义引脚或标识符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7288757/