【问题标题】:Swift MKPointAnnotation custom ImageSwift MKPointAnnotation 自定义图像
【发布时间】:2014-09-02 13:34:58
【问题描述】:

我尝试快速为我的 MKPointAnnotation 创建一个自定义“徽章”,但它失败了,因为 MKPointAnnotation 没有像图像这样的任何属性

 var information = MKPointAnnotation()
    information.coordinate = location 
    information.title = "Test Title!"
    information.subtitle = "Subtitle"
    information.image = UIImage(named: "dot.png") //this is the line whats wrong
    Map.addAnnotation(information)

有人想出了一个快速的解决方案吗?

【问题讨论】:

标签: ios swift mapkit mkpointannotation


【解决方案1】:
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {

    if !(annotation is MKPointAnnotation) {
        return nil
    }

    var annotationView = mapView.dequeueReusableAnnotationViewWithIdentifier("demo")
    if annotationView == nil {
        annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: "demo")
        annotationView!.canShowCallout = true
    }
    else {
        annotationView!.annotation = annotation
    }

    annotationView!.image = UIImage(named: "image")

    return annotationView

}

【讨论】:

  • 也请添加一些解释。
猜你喜欢
  • 1970-01-01
  • 2020-10-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-03
相关资源
最近更新 更多