Mapbox iOS move attribution Button

南笙酒味 提交于 2019-12-24 07:47:26

问题


I'm using the mapbox SDK and I need to show their logo watermark and their attribution mark. I can move them though, so I want to move the attribution button from the bottom right to bottom left next to the logo watermark.

I tried the following code but it did not work:

func mapViewWillStartLoadingMap(_ mapView: MGLMapView) {
    mapView.attributionButton.frame.offsetBy(dx: -200.0, dy: 0)
}

This is how it looks like:


回答1:


mapView.attributionButton.contentHorizontalAlignment = .left
mapView.attributionButton.frame.size = CGSize(width:   self.mapView.frame.size.width - 120, height: 25)

you can also hide attribution Button as follow:

mapView.attributionButton.alpha = 0



回答2:


I tried solutions like Harshal's but couldn't get that to work. Here's what worked for me (placing the attribution button near upper left). (Code added to viewDidLoad())

self.view.addConstraints([
NSLayoutConstraint(item: mapView.attributionButton, attribute: .width, relatedBy: .equal, toItem: nil, attribute: .width, multiplier: 1.0, constant: 25),
NSLayoutConstraint(item: mapView.attributionButton, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .height, multiplier: 1.0, constant: 25),
NSLayoutConstraint(item: mapView.attributionButton, attribute: .left, relatedBy: .equal, toItem: self.view, attribute: .left, multiplier: 1.0, constant: 72),
NSLayoutConstraint(item: mapView.attributionButton, attribute: .top, relatedBy: .equal, toItem: self.view, attribute: .top, multiplier: 1.0, constant: 24),
])



回答3:


Take a look at scaleBarPosition in MGLMapView

MapBox added the ability to do this in 4.3.0 https://github.com/mapbox/mapbox-gl-native/commit/60ceac5efc3d77199f773f08400fe1d53d5a1b90



来源:https://stackoverflow.com/questions/47792435/mapbox-ios-move-attribution-button

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!