Fos*_*nce 3 ios apple-maps swift swift3
基于此,可以在iOS的Google Maps上添加标记标签/徽章- 在ios的 Google Map 上的自定义标记上添加文本
有谁知道如何为Apple Maps做到这一点?我需要这样的东西:
您可以尝试如下操作,将UILabel图像放在图片上:
func mapView(_ mapView: MKMapView,
viewFor annotation: MKAnnotation) -> MKAnnotationView? {
// Leave default annotation for user location
if annotation is MKUserLocation {
return nil
}
let reuseID = "Location"
var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: reuseID)
if annotationView == nil {
let pin = MKAnnotationView(annotation: annotation,
reuseIdentifier: reuseID)
pin.image = UIImage(named: "cabifyPin")
pin.isEnabled = true
pin.canShowCallout = true
let label = UILabel(frame: CGRect(x: 0, y: 0, width: 30, height: 30))
label.textColor = .white
label.text = annotation.id // set text here
pin.addSubview(label)
annotationView = pin
} else {
annotationView?.annotation = annotation
}
return annotationView
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2729 次 |
| 最近记录: |