Mapbox iOS移动归因按钮

时间:2017-12-13 11:56:49

标签: ios swift mapbox

我正在使用mapbox SDK,我需要显示他们的徽标水印及其归属标记。我可以移动它们,所以我想从徽标水印旁边的右下角到左下角移动归因按钮。

我尝试了以下代码,但它不起作用:

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

这是它的样子: enter image description here

3 个答案:

答案 0 :(得分:2)

enter image description here

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

您还可以隐藏归因按钮,如下所示:

mapView.attributionButton.alpha = 0

答案 1 :(得分:0)

我尝试了类似Harshal的解决方案,但无法正常工作。这对我有用(将属性按钮放在左上角附近)。 (代码已添加到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),
])

答案 2 :(得分:0)

scaleBarPosition中查看MGLMapView

MapBox在4.3.0中添加了执行此操作的功能 https://github.com/mapbox/mapbox-gl-native/commit/60ceac5efc3d77199f773f08400fe1d53d5a1b90