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 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)

关于ios - swift 上的自定义标记图像(MapKit),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30262269/

相关文章:

iphone - 从 Phonegap 过渡到原生应用

ios - Alamofire httpBody 在 swift 5 中显示 500 statusCode

ios - 处理 RxSwift 重试和错误处理的最佳实践是什么

ios - 从服务器加载 MKMapKit 叠加瓦片

javascript - 如何从javascript调用swift函数

swift - 无法获取 extensionBundleID 的描述符

ios - 将图像从 iOS 应用程序发送到服务器的正确方法

ios - 位置跟踪器图标未显示在 map 上

ios - 经纬度点的奇怪位置

ios - 如何从iPhone SDK中的其他应用程序打开 map 应用程序