Ios swift上的自定义标记图像(MapKit)

Ios swift上的自定义标记图像(MapKit),ios,swift,mapkit,Ios,Swift,Mapkit,我在MapKit上使用自定义标记 如何更改自定义标记上的图像宽度和高度 我的代码: func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! { if (annotation is MKUserLocation) { return nil } let reuseId = "test" var an

我在MapKit上使用自定义标记

如何更改自定义标记上的图像宽度和高度

我的代码:

func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {

    if (annotation is MKUserLocation) {
        return nil
    }

    let reuseId = "test"

    var anView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId)
    if anView == nil {

        anView = MKAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
        anView.image = UIImage(named:"x2.png")
        anView.canShowCallout = true
    }
    else {
        anView.annotation = annotation
    }
    return anView
}
尝试使用

anView.frame.size = CGSize(width: 30.0, height: 30.0)
MapKit ViewForAnnotation委托应该是

 func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
    
let pin = mapView.view(for: annotation) ?? MKAnnotationView(annotation: annotation, reuseIdentifier: nil)
    if annotation is MKUserLocation {
           pin.image = //Image for Current Location Pin
           return pin
         } else {
             pin.image = //Image for Other Pin
             return pin
          }
     }

一个选项是,您可以根据需要设置图像大小,然后可以显示它。
 func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
    
let pin = mapView.view(for: annotation) ?? MKAnnotationView(annotation: annotation, reuseIdentifier: nil)
    if annotation is MKUserLocation {
           pin.image = //Image for Current Location Pin
           return pin
         } else {
             pin.image = //Image for Other Pin
             return pin
          }
     }