问题
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