2016-11-29 75 views
1

我在那裏停留了一段時間,我想知道有人可以幫助我。我們知道MKAnnotationView.Image =一些圖像,將所有的pin設置爲這個圖像。如何爲不同的針腳設置不同的圖像。通常情況下,循環可以將一個引腳標記爲一個圖像,但使用MKAnnotationView.Image時,如何設置它。如何爲每個引腳設置不同的圖像? Xamarin iOS

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://github.com/xamarin/xamarin-forms-samples/blob/master/CustomRenderers/Map/iOS/CustomMapRenderer.cs

官方公會自定義地圖是有https://developer.xamarin.com/guides/xamarin-forms/custom-renderer/map/

回答

1

這是我在Xamarin論壇上找到。

annotationView.Image = UIImage.FromFile ("pin.png"); 

,如果您有任何圖像,只需登錄圖像轉換成annotationView.Image。您可以將圖像標識存儲在我的定製引腳中。因此,您只需將圖像標識指向您想要使用的正確圖像即可。

類似於annotationView.Image = UIImage.FromFile (customPin.Image)這是你想要的東西嗎?

相關問題