【问题标题】:MKMarkerAnnotationView cluster colorMKMarkerAnnotationView 集群颜色
【发布时间】:2017-10-13 08:56:45
【问题描述】:

我一直在尝试新的 iOS 11 MKMarkerAnnotationView,最后集群就像一个魅力。但问题是,如您在图片中看到的,这些簇的颜色错误。我该如何控制呢?

【问题讨论】:

    标签: mapkit ios11 mapkitannotation


    【解决方案1】:

    没关系,我设法弄明白了。

    我在代理的mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) 函数中添加了以下内容。

    if let cluster = annotation as? MKClusterAnnotation {
        let markerAnnotationView = MKMarkerAnnotationView()
        markerAnnotationView.glyphText = String(cluster.memberAnnotations.count)
        markerAnnotationView.markerTintColor = UIColor.appPrimary
        markerAnnotationView.canShowCallout = false
    
        return markerAnnotationView
    }
    

    【讨论】:

      【解决方案2】:

      如果你不使用MKMapViewDelegate,你可以在你的MKMarkerAnnotationView子类中设置,

      clusteringIdentifier = MKMapViewDefaultClusterAnnotationViewReuseIdentifier
      

      在你的视图控制器中

      mapView.register(SubclassMarkerView.self, forAnnotationViewWithReuseIdentifier: MKMapViewDefaultAnnotationViewReuseIdentifier)
      
      mapView.register(SubclassMarkerView.self, forAnnotationViewWithReuseIdentifier: MKMapViewDefaultClusterAnnotationViewReuseIdentifier)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-03-15
        • 1970-01-01
        • 1970-01-01
        • 2021-11-03
        • 2020-04-03
        • 2020-11-01
        • 2021-04-05
        • 2017-08-16
        相关资源
        最近更新 更多