I’ve been trying out the new iOS 11 MKMarkerAnnotationView, and finally clustering works like a charm. But the problem is that the clusters have the wrong color as you can see in the picture. How can I control this?
MKMarkerAnnotationView cluster color
Asked Answered
Nevermind I managed to figure it out.
I added the following to the mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation)
function of the delegate.
if let cluster = annotation as? MKClusterAnnotation {
let markerAnnotationView = MKMarkerAnnotationView()
markerAnnotationView.glyphText = String(cluster.memberAnnotations.count)
markerAnnotationView.markerTintColor = UIColor.appPrimary
markerAnnotationView.canShowCallout = false
return markerAnnotationView
}
if you are not using MKMapViewDelegate
you can just set, in your MKMarkerAnnotationView
subclass,
clusteringIdentifier = MKMapViewDefaultClusterAnnotationViewReuseIdentifier
and in your view controller
mapView.register(SubclassMarkerView.self, forAnnotationViewWithReuseIdentifier: MKMapViewDefaultAnnotationViewReuseIdentifier)
mapView.register(SubclassMarkerView.self, forAnnotationViewWithReuseIdentifier: MKMapViewDefaultClusterAnnotationViewReuseIdentifier)
© 2022 - 2024 — McMap. All rights reserved.