Fab*_*gue 3 mapkit ios mkpointannotation swift
我尝试在swift中为我的MKPointAnnotation创建一个自定义的"badget",但它失败了,因为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)
Run Code Online (Sandbox Code Playgroud)
有人想出了一个快速的解决方案吗?
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
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9415 次 |
| 最近记录: |