改变市场中集群注释的颜色。 iOS,Swift

问题描述 投票:2回答:1

我正在尝试更改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
    }
ios swift mapkit markerclusterer
1个回答
5
投票

使用markerTintColor

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

EG

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
}
© www.soinside.com 2019 - 2024. All rights reserved.