更改市场中集群注释的颜色。 iOS、Swift
Change colour of cluster annotation in market. iOS, Swift
我正在尝试更改 iOS、swift.
的集群注释 mapkit 的默认颜色
可以吗。我可以更改单个注释,但不能更改群集。
下面是我的代码。
@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、swift.
的集群注释 mapkit 的默认颜色可以吗。我可以更改单个注释,但不能更改群集。
下面是我的代码。
@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
}