2015-04-05 67 views

回答

7

您可以實現markerInfoWindow method從GMSMapViewDelegate

樣品實施以顯示斯威夫特的自定義信息窗口:

func mapView(mapView: GMSMapView!, markerInfoWindow marker: GMSMarker!) -> UIView! { 
     var infoWindow = NSBundle.mainBundle().loadNibNamed("CustomInfoWindow", owner: self, options: nil).first! as CustomInfoWindow 
     infoWindow.label.text = "\(marker.position.latitude) \(marker.position.longitude)" 
     return infoWindow 
} 

您可以查看詳細的實施參觀this GitHub page

取決於你希望你的信息窗口的樣子,你可以通過執行infoWindow.backgroundColor = UIColor.redColor()改變背景顏色,或者做infoWindow.layer.cornerRadius = 10.0f改變你的信息窗口的形狀,甚至可以通過做infoWindow.imageView.image = UIImage(named: "image.jpg")添加圖像。

+0

有沒有辦法讓這個看起來更像一個信息窗口,而不是一個方形框。 – user3280937 2015-04-07 11:24:50

+0

請參閱我編輯的答案@ user3280937,這實際上取決於您希望信息窗口的外觀如何,您可以在xib文件中進行大量自定義或在代碼中進行自定義。 – ztan 2015-04-07 15:56:39

+0

它交給viewcontroller,我該如何解決它? – 2016-05-04 12:42:43

相關問題