gpt4 book ai didi

swift - 将注释更改为引脚

转载 作者:行者123 更新时间:2023-11-30 11:18:34 24 4
gpt4 key购买 nike

我正在尝试制作一个图钉,您单击它就会出现标题和副标题。

这是我到目前为止的代码:

    let span : MKCoordinateSpan = MKCoordinateSpanMake(0.1, 0.1)
let location : CLLocationCoordinate2D = CLLocationCoordinate2DMake(40.750517, -73.987271)
let region : MKCoordinateRegion = MKCoordinateRegionMake(location, span)
mapView.setRegion(region, animated: true)

let annotation = MKPointAnnotation()

annotation.coordinate = location
annotation.title = "Bus Stop"
annotation.subtitle = "Street Name at Street Name"
mapView.addAnnotation(annotation)

问题是我的出现为一个圆形气泡,这不是我想要的,我希望在应用程序中使用那些传统的红色图钉,当您单击更多信息时会显示。

最佳答案

扩展 YourViewC:MKMapViewDelegate {

    func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
if annotation is MKUserLocation
{
return nil
}
var annotationView = self.mapView.dequeueReusableAnnotationView(withIdentifier: "CustomPin")
if annotationView == nil{
annotationView = AnnotationView(annotation: annotation, reuseIdentifier: "CustomPin")
annotationView?.canShowCallout = false
}else{
annotationView?.annotation = annotation
}
annotationView?.image = UIImage(named: "bluecircle") // Pass name of your custom image
return annotationView
}
func mapView(_ mapView: MKMapView,
didSelect view: MKAnnotationView){
let annotation = view.annotation as? CustomAnnotation
print(annotation?.address) // get info you passed on pin

// write code here to add custom view on tapped annotion

}

关于swift - 将注释更改为引脚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51537295/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com