2017-04-20 62 views
0

自定义视图至于我读的境界文档在地图集群中还有一类ABFClusterAnnotationView具有几个特性:countcolorcountLabel但我找不到任何地方的注释image。这是override与添加image属性?我设法添加images通过使用默认注释iside mapView委托方法,但从那里我无法管理的群集计数。我只想在地图上只有1个值的地方更改图片。的境界地图集群

所以没有什么猫腻,简单设置图像的注释:

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

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

     return annView 
    } 

提前感谢!

回答

1

恕我直言图片属性不覆盖。但无论如何,您仍然有以下几种选择:

  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 
     } 
} 
+0

是啊,那是很酷的答案!但是它不会影响'MyAnnotation',因为默认情况下所有的注释都来自Realm库。 – yerpy