【发布时间】:2017-04-13 13:28:21
【问题描述】:
我停在那里一会儿,我想知道有人可以帮助我。我们知道 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");将所有引脚设置为此图像。但是,通常人们希望每个引脚都有不同的图像。任何想法,我都非常感谢。
官方公会自定义地图有https://developer.xamarin.com/guides/xamarin-forms/custom-renderer/map/
【问题讨论】:
标签: ios xamarin xamarin.ios