如何解决swift - 更改注释视图按钮
我正在寻找有关 annotationView 的帮助。我要做的是已经在注释中添加了图标,但是当我要点击注释(图标)时,我希望在注释视图框架中看到按钮,如下所示:
我在旧讨论中寻求帮助,但没有找到答案: UIButton in AnnotationView - How to keep icon and button
这是我的视频:
override func viewDidLoad() {
super.viewDidLoad()
mapView.register(MKMarkerAnnotationView.self,forAnnotationViewWithReuseIdentifier: "identifier") \\ important part
checkLocationServices()
znajdzSzczytyNaMapie(szczyty)
circles = szczyty.map {
MKCircle(center: $0.coordinate,radius: 100)
}
mapView.addOverlays(circles!)
mapView.delegate = self
}
在 viewdidload 中,我在 viewdidload 中添加了 mapView.register(MKMarkerAnnotationView.self,forAnnotationViewWithReuseIdentifier: "identifier")
以注册标识符。
其余代码如下:
func mapView(_ mapView: MKMapView,viewFor annotation: MKAnnotation) -> MKAnnotationView? {
guard !(annotation is MKUserLocation) else { return nil }
//let annotationView = MKMarkerAnnotationView(annotation: annotation,reuseIdentifier: "MyMarker")
let identifier = "identifier"
//guard let annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier) as? MKMarkerAnnotationView else { return nil }
guard let annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier,for: annotation) as? MKMarkerAnnotationView else { return nil }
let btn = UIButton(type: .detaildisclosure)
annotationView.rightCalloutAccessoryView = btn
switch annotation.title!! {
ase "Turbacz":
annotationView.markerTintColor = UIColor(red: 0.86,green: 0.99,blue: 0.79,alpha: 1.00)
annotationView.glyphImage = UIImage(named: "bald")
case "example":
annotationView.markerTintColor = UIColor(red: 0.80,green: 0.98,blue: 0.73,alpha: 1.00)
annotationView.glyphImage = UIImage(named: "bear")
default:
annotationView.markerTintColor = UIColor.green
annotationView.glyphImage = UIImage(named: "gora")
}
return annotationView
}
但我还是明白了:
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。