在此基础上在斯威夫特

问题描述:

在苹果地图上添加标识标签,有可能对谷歌地图添加标记标签/徽章的iOS - Add text on custom marker on google map for ios在此基础上在斯威夫特

有谁知道如何做到这一点的苹果地图?我需要的是这样的:

enter image description here

+0

你的意思'MKAnnotationView's?链接到文档:https://developer.apple.com/reference/mapkit/mkannotationview或只是在互联网上搜索教程。 –

+0

您无法在Apple地图上进行此操作,但您可以在自己的应用程序的地图视图中执行此操作。 – matt

你可以尝试这样的事情把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 
    } 
+0

谢谢,我会试试:) – FosAvance