使用 Google 地图 iOS sdk 快速创建自定义信息窗口? [英] Creating custom info window in swift with the Google maps iOS sdk?

查看:17
本文介绍了使用 Google 地图 iOS sdk 快速创建自定义信息窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个 xib 和一个视图控制器,并希望在 swift 中为它显示一个自定义的信息窗口作为标记.在网上搜索后,我找到了一个关于 OBJ-C 的旧教程,但这对我没有帮助.

I have created a xib and a view controller, and want to display it a customised info window for a marker in swift. After searching on the Internet I have found an old tutorial in OBJ-C however this will not help me.

谢谢.

推荐答案

你可以实现 markerInfoWindow 方法 来自 GMSMapViewDelegate

You can implement the markerInfoWindow method from GMSMapViewDelegate

在 Swift 中显示自定义信息窗口的示例实现:

Sample implementation to show an custom info window in Swift:

 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
 }

您可以访问这个GitHub页面了解详情实施.

You can visit this GitHub page for detail implementation.

取决于您希望信息窗口的外观,您可以通过执行 infoWindow.backgroundColor = UIColor.redColor() 来更改背景颜色,或者通过执行 infoWindow.layer.cornerRadius = 10.0f,甚至可以通过 infoWindow.imageView.image = UIImage(named: "image.jpg") 来添加图片.

Depends on how you want your info window looks like, you can change the background color by doing infoWindow.backgroundColor = UIColor.redColor(), or change the shape of your info window by doing infoWindow.layer.cornerRadius = 10.0f, or even add an image by doing infoWindow.imageView.image = UIImage(named: "image.jpg").

这篇关于使用 Google 地图 iOS sdk 快速创建自定义信息窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆