当前位置:  开发笔记 > 编程语言 > 正文

如何在Mapview swift ios中设置自定义图像?

如何解决《如何在Mapviewswiftios中设置自定义图像?》经验,为你挑选了1个好方法。



1> Lalit kumar..:
  mapview.delegate = self

    func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
guard !(annotation is MKUserLocation) else {
    return nil
}

 let annotationIdentifier = "Identifier"
 var annotationView: MKAnnotationView?
 if let dequeuedAnnotationView = mapView.dequeueReusableAnnotationView(withIdentifier: annotationIdentifier) {
    annotationView = dequeuedAnnotationView
    annotationView?.annotation = annotation
}
else {
    annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: annotationIdentifier)
    annotationView?.rightCalloutAccessoryView = UIButton(type: .detailDisclosure)
}

 if let annotationView = annotationView {

    annotationView.canShowCallout = true
    annotationView.image = UIImage(named: "yourImagename”)
}
  return annotationView
}

推荐阅读
Chloemw
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有