我停在那里一会儿,我想知道有人可以帮助我。我们知道 MKAnnotationView.Image = some image,会将所有的 pin 设置为这张图片。如何为不同的引脚设置不同的图像。通常,有一个for循环将一个pin标记为一个图像,但是对于MKAnnotationView.Image,如何设置它。
MKAnnotationView GetViewForAnnotation (MKMapView mapView, IMKAnnotation annotation)
{
MKAnnotationView annotationView = null;
if (annotation is MKUserLocation)
return null;
var anno = annotation as MKPointAnnotation;
var customPin = GetCustomPin (anno);
if (customPin == null) {
throw new Exception ("Custom pin not found");
}
annotationView = mapView.DequeueReusableAnnotation (customPin.Id);
if (annotationView == null) {
annotationView = new CustomMKAnnotationView (annotation, customPin.Id);
annotationView.Image = UIImage.FromFile ("pin.png");
annotationView.CalloutOffset = new CGPoint (0, 0);
annotationView.LeftCalloutAccessoryView = new UIImageView (UIImage.FromFile ("monkey.png"));
annotationView.RightCalloutAccessoryView = UIButton.FromType (UIButtonType.DetailDisclosure);
((CustomMKAnnotationView)annotationView).Id = customPin.Id;
((CustomMKAnnotationView)annotationView).Url = customPin.Url;
}
annotationView.CanShowCallout = true;
return annotationView;
}
annotationView.Image = UIImage.FromFile ("pin.png");会将所有 pin 设置为此图像。但是,通常人们希望每个图钉都有不同的图像。任何想法,我真的很感激。
有官方公会自定义 map https://developer.xamarin.com/guides/xamarin-forms/custom-renderer/map/
最佳答案
这是我在 Xamarin 论坛中找到的内容。
annotationView.Image = UIImage.FromFile ("pin.png");
如果你有任何图像,只需将图像签名到 annotationView.Image 中。您可以将图像标识存储在我的自定义 pin 中。因此,您只需使用图像标识来指出您要使用的正确图像。
类似于 annotationView.Image = UIImage.FromFile (customPin.Image)
这是你想要的吗?
关于ios - 如何为每个图钉设置不同的图像? Xamarin iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40867783/