2017-04-20 81 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