所以到目前为止,我只有默认的MKMapView引脚工作。但是我想要一个自定义图像来替换那个小红色别针。这是我在下面看到的。我错过了什么?我认为定义 view.image 可以解决问题,但我想不会。
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:
(id<MKAnnotation>)annotation {
MKPinAnnotationView *view = [[MKPinAnnotationView alloc]
initWithAnnotation:annotation reuseIdentifier:@"pin"];
view.enabled = YES;
view.animatesDrop = YES;
view.canShowCallout = YES;
view.image = [UIImage imageNamed:@"custom-pin-image.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage
imageNamed:@"custom-image-for-annotation.png"]];
view.leftCalloutAccessoryView = imageView;
view.rightCalloutAccessoryView = [UIButton buttonWithType:
UIButtonTypeDetailDisclosure];
return view;
}
MKPinAnnotationView
是MKAnnotationView
的子类,它具有image属性,但它忽略了它,而是显示默认的引脚图像。
您应该改用MKAnnotationView
。
此外,请确保您的MKMapView
代理未被激活。