【发布时间】:2011-08-05 07:43:17
【问题描述】:
朋友们好, 我正在开发一种功能来在地图图钉上显示索引号并在 iPhone 的地图视图上设置图像,所以请告诉我任何链接或任何想法来开发此功能。
提前致谢。
【问题讨论】:
标签: mkmapview
朋友们好, 我正在开发一种功能来在地图图钉上显示索引号并在 iPhone 的地图视图上设置图像,所以请告诉我任何链接或任何想法来开发此功能。
提前致谢。
【问题讨论】:
标签: mkmapview
上下文中的索引号是什么?您的代码显示的只是一个数字吗?如果是这样,您的问题是如何在地图上显示文本。使用地图叠加层。图像也一样。搜索 MKMapOverlay 并从那里开始。
【讨论】:
我已经在注释视图中使用此方法作为索引号。
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
guard !(annotation is MKUserLocation) else {
return nil
}
// Better to make this class property
let annotationIdentifier = "AnnotationIdentifier"
var annotationView = MKAnnotationView()
annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: annotationIdentifier)
annotationView.frame = CGRect(x: annotationView.frame.origin.x, y: annotationView.frame.origin.y, width: 80, height: 200)
annotationView.annotation = annotation
annotationView.tag = index
index += 1
let imageViewPin = UIImageView(frame: CGRect(x: 0, y: 0, width: 30, height: 40))
imageViewPin.center = CGPoint(x: annotationView.center.x, y: annotationView.center.y - 11)
imageViewPin.image = UIImage(named: "green_pin")
annotationView.addSubview(imageViewPin)
return annotationView
}
func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
debugPrint(view.tag)
}
【讨论】: