【问题标题】:How to set a different image for each pin? Xamarin iOS如何为每个引脚设置不同的图像? Xamarin iOS
【发布时间】: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://github.com/xamarin/xamarin-forms-samples/blob/master/CustomRenderers/Map/iOS/CustomMapRenderer.cs

官方公会自定义地图有https://developer.xamarin.com/guides/xamarin-forms/custom-renderer/map/

【问题讨论】:

    标签: ios xamarin xamarin.ios


    【解决方案1】:

    这是我在 Xamarin 论坛中找到的。

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

    如果您有任何图像,只需将图像登录到 annotationView.Image。您可以将图像标识存储在我的自定义图钉中。因此,您只需将图像标识指出您要使用的正确图像。

    类似annotationView.Image = UIImage.FromFile (customPin.Image) 这是你想要的吗?

    【讨论】:

      猜你喜欢
      • 2013-08-04
      • 1970-01-01
      • 2019-01-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多