gpt4 book ai didi

swift - Realm map 集群的自定义 View

转载 作者:行者123 更新时间:2023-11-28 15:42:48 25 4
gpt4 key购买 nike

据我阅读有关 map 聚类的 Realm 文档,有一个类 ABFClusterAnnotationView,它有几个属性:countcolorcountLabel 但我无法在任何地方找到 image 进行注释。是否可以通过添加 image 属性来覆盖?我设法通过使用默认注释 iside mapView 委托(delegate)方法添加 images 但从那里我无法管理集群的数量。我只想在 map 上只有 1 个值的图钉的地方更改图像。

所以没有什么棘手的,简单的为注释设置图像:

 func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {

let annView = MKAnnotationView(annotation: annotation, reuseIdentifier: "test")
annView.image = myImage

return annView
}

提前致谢!

最佳答案

恕我直言,图像属性未被覆盖。但无论如何你还有几个选择:

  1. 不要使用 ABFClusterAnnotationView。 (使用例如 MKAnnotationView)
  2. 使用FBAnnotationClusterView,设置 FBAnnotationClusterViewConfiguration 并在模板中使用 FBAnnotationClusterDisplayMode.Image(imageName)
  3. 使用不同的库 - https://github.com/efremidze/Cluster

广告 1)

override func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
switch annotation {
case _ as MyAnnotation:
// use MKAnnotationView
let reuseId = "Pin"
return mapView.dequeueReusableAnnotationView(withIdentifier: reuseId) as? MKPinAnnotationView ?? MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
case let fbAnnotation as FBAnnotationCluster:
let reuseId = "Cluster"
let clusterView = mapView.dequeueReusableAnnotationView(withIdentifier: reuseId) ?? FBAnnotationClusterView(annotation: fbAnnotation, reuseIdentifier: reuseId, configuration: FBAnnotationClusterViewConfiguration.default())
return clusterView
default:
return nil
}
}

关于swift - Realm map 集群的自定义 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43519560/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com