12

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.

Legal sign in bottom left corner

Braiam
  • 1
  • 11
  • 47
  • 78
Fabian Lundberg
  • 205
  • 3
  • 6

11 Answers11

13

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)
DBD
  • 23,075
  • 12
  • 60
  • 84
Andre Simon
  • 665
  • 10
  • 16
  • Thank you! Works perfectly. – jnoor Jan 20 '16 at 20:08
  • 1
    It 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
  • 1
    Im testing this against iOS 10, Xcode 8.1 and my annotations are fine. No issues here... – Jeff Nov 09 '16 at 18:53
  • 1
    This 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
10

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);
Sascha
  • 5,903
  • 3
  • 24
  • 20
8

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);
Chuckels5584
  • 551
  • 2
  • 6
  • 17
7

These methods no longer work on iOS 7. Correct way is to specify bottomLayoutGuide on your UIViewController. Described in detail here

Den Telezhkin
  • 633
  • 6
  • 9
3

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

Community
  • 1
  • 1
  • 2
    I'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
1

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
Zeeshan
  • 4,194
  • 28
  • 32
1

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
  }
}
Anton Plebanovich
  • 1,296
  • 17
  • 17
  • 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
1

@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)
    }
}
1

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)
Community
  • 1
  • 1
Mojtaba Hosseini
  • 95,414
  • 31
  • 268
  • 278
0

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
}
Jens Schwarzer
  • 2,840
  • 1
  • 22
  • 35
0

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)
}
Dmytro Skorokhod
  • 424
  • 8
  • 17