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

Vyk*_*tas 4 mapkit ios swift

我在 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
}
Run Code Online (Sandbox Code Playgroud)

Ner*_*tor 5

尝试使用

anView.frame.size = CGSize(width: 30.0, height: 30.0)
Run Code Online (Sandbox Code Playgroud)