【发布时间】:2018-07-09 10:42:30
【问题描述】:
我正在使用 Swift 3 和 Xcode 10 beta 3,我需要为我在地图上的图钉使用自定义图像。在另一个帖子上的一个人的帮助下,我们编写了这段代码,除了引脚仍然是默认值之外,它都可以正常工作。
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
if let annotation = annotation as? Annotation {
let identifier = "identifier"
let annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: identifier)
annotationView.image = annotation.image //add this
annotationView.canShowCallout = true
annotationView.calloutOffset = CGPoint(x: -5, y: 5)
annotationView.rightCalloutAccessoryView = UIButton(type: .detailDisclosure) as UIView
return annotationView
}
return nil
}
let marker = Annotation(title: "LVR" , subtitle: "" , coordinate: CLLocationCoordinate2D(latitude: 43.772523, longitude: 11.254356))
marker.image = UIImage(named: "antonioli.png")
//mapView.addAnnotation(marker)
self.map.addAnnotation(marker)
我应该如何处理这个问题?
【问题讨论】: