I wonder if anyone know how you move the legal sign on a mapview, right now my toolbar is covering it. Does anyone know how? There is lot's of help with the google logo but nothing on the apple maps.
11 Answers
In Swift:
mapView.layoutMargins = UIEdgeInsetsMake(top, right, -20, left)
I tested this in OS9 and it works.
Swift 5.2
// -20 will make the legal disclaimer move down. If you want the
// disclaimer to move up, use a positive number.
mapView.layoutMargins = UIEdgeInsets(top: 0, left: 0, bottom: -20, right: 0)
- 22,695
- 12
- 59
- 84
- 645
- 9
- 15
-
Thank you! Works perfectly. – jnoor Jan 20 '16 at 20:08
-
1It seems like this doesn't work when compiled against iOS 10 SDK. – Jens Schwarzer Oct 13 '16 at 09:24
-
Claraification: When compiled against iOS 10 SDK this solution unfortunately have an impact of `MapView.showAnnotations`, i.e., annotations will get an offset applied. In my case annotations are no longer visible :S – Jens Schwarzer Oct 13 '16 at 10:16
-
1Im testing this against iOS 10, Xcode 8.1 and my annotations are fine. No issues here... – Jeff Nov 09 '16 at 18:53
-
1This worked for me with iOS 12 and Swift 4: [https://stackoverflow.com/a/51534779/1359088](https://stackoverflow.com/a/51534779/1359088) – James Toomey Oct 19 '18 at 00:36
This should work, although I'm not sure whether Apple will allow you to do that
UILabel *attributionLabel = [mapView.subviews objectAtIndex:1];
attributionLabel.center = CGPointMake(attributionLabel.center.x, attributionLabel.center.y - 44.0f);
- 5,803
- 3
- 23
- 20
-
Works great, not sure if appel will accept it but I will check! – Fabian Lundberg Nov 03 '12 at 00:54
-
1
-
For some reason the second time I display the map this will reset the position. I hardcoded it and that works. – Alper Sep 10 '14 at 21:35
This is still possible in iOS 7, but only (?) if placed in viewDidAppear.
The coords are reset if placed in viewDidLoad or viewWillAppear.
UILabel *attributionLabel = [mapView.subviews objectAtIndex:1];
attributionLabel.center = CGPointMake(attributionLabel.center.x, attributionLabel.center.y - 44.0f);
- 551
- 2
- 6
- 16
-
I have actually not found this to be the case. In my case, `viewDidLoad` was the correct place to put it. – James Billingham Apr 19 '14 at 11:50
These methods no longer work on iOS 7. Correct way is to specify bottomLayoutGuide on your UIViewController. Described in detail here
- 636
- 6
- 9
Changing the position doesn't quite work, however hiding the "Legal" button works perfectly.
[[mapView.subviews objectAtIndex:1] setHidden:YES]
EDIT:
Swift 2.0 iOS equivalent
mapView.subviews[1].isHidden = true
- 1
- 1
- 47
- 1
-
2I'm pretty sure doing this might land you in trouble submitting to the app store. If not, it seems like it could at some point. I'd personally shy away from this one. – KellyHuberty Sep 19 '16 at 16:32
Carrying on Skeet Skeet point .
I implemented your approach it worked well but after coming in the viewcontroller multiple times legal label y keeps on decreasing as you see the logic it always displaces itself. so instead changing centre i propose
we change frame
UILabel *attributionLabel = [mapView.subviews objectAtIndex:1];
attributionLabel.frame = CGRectMake(20, self.view.frame.size.height - 135, attributionLabel.frame.size.width, attributionLabel.frame.size.height);
\\135 is height of your bottom view that was hiding legal
- 4,086
- 26
- 32
-
1Thank you! This was the only solution I have found to work properly when compiling against iOS 10 SDK :D – Jens Schwarzer Oct 13 '16 at 13:38
I wrote extension that worked for me. It can be used in animation block to animate those changes:
import MapKit
extension MKMapView {
/// Workaround for layoutMargins bug.
func setLegalInsets(left: CGFloat, bottom: CGFloat) {
let oldLeft = layoutMargins.left
let oldBottom = layoutMargins.bottom
let lblLegal = (subviews.filter { view in
return view is UILabel
}).first
lblLegal?.frame.origin.x += left - oldLeft
lblLegal?.frame.origin.y -= bottom - oldBottom
layoutMargins.left = left
layoutMargins.bottom = bottom
}
}
- 1,122
- 15
- 15
-
When compiled against iOS 10 SDK this solution unfortunately have an impact of `MapView.showAnnotations`, i.e., annotations will get an offset applied. In my case annotations are no longer visible :S – Jens Schwarzer Oct 13 '16 at 10:16
@Dymtro's answer works well for me, but I would suggest checking the size of the subviews first. This should at least prevent possible crashes if the view hierarchy changes in the future:
override func viewWillLayoutSubviews() {
positionLegalMapLabel()
}
func positionLegalMapLabel() {
if self.mapView.subviews.count > 1 {
let legalMapLabel = self.mapView.subviews[1]
legalMapLabel.frame.origin = CGPointMake(self.mapView.bounds.size.width - legalMapLabel.frame.size.width - 7, legalMapLabel.frame.origin.y)
}
}
- 23
- 1
- 5
Swift 4+
You can change the position of those by setting the layoutMargins of the mapView.
For example this will push it off from the bottom:
mapView.layoutMargins.bottom = -100
Also you can change edge insets you need all at once:
mapView.layoutMargins = UIEdgeInsets(top: 0, left: 0, bottom: -100, right: 0)
- 1
- 1
- 71,072
- 19
- 226
- 225
A Swift 3 example based on @xeieshan's example that works when compiled against iOS 10 SDK. In my example I have a transparent bar in the bottom that animates up when the map view is being present. The label repositioning can also be animated.
// reposition the 'Legal' label above the transparent bottom bar
// unfortunately there is no safe way to identify the label but it is the last subview - hopefully this will not change
if let legalLabel = mapView.subviews.last {
var frame = legalLabel.frame
frame.origin.y = frame.origin.y - self.bottomBar.bounds.size.height // reposition it above the bottom bar
legalLabel.frame = frame
}
- 2,648
- 1
- 21
- 35
Use viewWillLayoutSubviews() instead of viewDidAppear() to avoid a jump.
override func viewWillLayoutSubviews() {
positionLegalMapLabel()
}
func positionLegalMapLabel() {
let legalMapLabel = self.mapView.subviews[1]
legalMapLabel.frame.origin = CGPointMake(self.mapView.bounds.size.width - legalMapLabel.frame.size.width - 7, legalMapLabel.frame.origin.y)
}
- 352
- 6
- 14