ios - 更改市场中集群注释的颜色。 iOS, swift

标签 ios swift mapkit markerclusterer

我正在尝试更改 iOS 集群注释 mapkit 的默认颜色,swift。

这可能吗?我可以更改单个注释,但不能更改集群。

下面是我的代码。

@available(iOS 11.0, *)
    func mapView(_ mapView: MKMapView, clusterAnnotationForMemberAnnotations memberAnnotations: [MKAnnotation]) -> MKClusterAnnotation {
        let vehicles = MKClusterAnnotation(memberAnnotations: memberAnnotations)
        vehicles.title = "Photos"
        vehicles.subtitle = nil
        return vehicles
    }

最佳答案

使用markerTintColor

https://developer.apple.com/documentation/mapkit/mkmarkerannotationview/2873822-markertintcolor

例如

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
    let identifier = "marker"
    var view: MKMarkerAnnotationView

    if let dequeuedView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier)
        as? MKMarkerAnnotationView {
        dequeuedView.annotation = annotation
        view = dequeuedView
    } else {
        view = MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: identifier)
        view.markerTintColor = .blue
    }
    return view
}

关于ios - 更改市场中集群注释的颜色。 iOS, swift ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47912995/

相关文章:

ios - MKMapView 中水平折线的缩放级别不正确

ios - 从 C 库调用 objective-c 方法

ios - 应用商店配置文件

ios - 如何检索healthkit数据并显示?

ios - UITableView 中的 NSUserDefaults 和持久性

swift - 通过点击 Mapkit 中的注释来触发 NavigationLink

iphone - 如何长按并抬起 MKAnnotationView

ios - 如何在swift中为uiimage添加彩色边框

ios - Swift:更新 UI - 主线程上的整个功能或只是 UI 更新?

ios - 在方向改变时改变整个用户界面