Guest User

Untitled

a guest
Oct 19th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. UILabel *attributionLabel = [mapView.subviews objectAtIndex:1];
  2. attributionLabel.center = CGPointMake(attributionLabel.center.x, attributionLabel.center.y - 44.0f);
  3.  
  4. mapView.layoutMargins = UIEdgeInsetsMake(top, right, -20, left)
  5.  
  6. UILabel *attributionLabel = [mapView.subviews objectAtIndex:1];
  7. attributionLabel.center = CGPointMake(attributionLabel.center.x, attributionLabel.center.y - 44.0f);
  8.  
  9. UILabel *attributionLabel = [mapView.subviews objectAtIndex:1];
  10. attributionLabel.frame = CGRectMake(20, self.view.frame.size.height - 135, attributionLabel.frame.size.width, attributionLabel.frame.size.height);
  11. \135 is height of your bottom view that was hiding legal
  12.  
  13. // reposition the 'Legal' label above the transparent bottom bar
  14. // unfortunately there is no safe way to identify the label but it is the last subview - hopefully this will not change 😱
  15. if let legalLabel = mapView.subviews.last {
  16. var frame = legalLabel.frame
  17. frame.origin.y = frame.origin.y - self.bottomBar.bounds.size.height // reposition it above the bottom bar
  18. legalLabel.frame = frame
  19. }
  20.  
  21. import MapKit
  22.  
  23. extension MKMapView {
  24.  
  25. /// Workaround for layoutMargins bug.
  26. func setLegalInsets(left: CGFloat, bottom: CGFloat) {
  27. let oldLeft = layoutMargins.left
  28. let oldBottom = layoutMargins.bottom
  29.  
  30. let lblLegal = (subviews.filter { view in
  31. return view is UILabel
  32. }).first
  33.  
  34. lblLegal?.frame.origin.x += left - oldLeft
  35. lblLegal?.frame.origin.y -= bottom - oldBottom
  36.  
  37. layoutMargins.left = left
  38. layoutMargins.bottom = bottom
  39. }
  40. }
  41.  
  42. override func viewWillLayoutSubviews() {
  43. positionLegalMapLabel()
  44. }
  45.  
  46. func positionLegalMapLabel() {
  47. let legalMapLabel = self.mapView.subviews[1]
  48.  
  49. legalMapLabel.frame.origin = CGPointMake(self.mapView.bounds.size.width - legalMapLabel.frame.size.width - 7, legalMapLabel.frame.origin.y)
  50. }
  51.  
  52. override func viewWillLayoutSubviews() {
  53. positionLegalMapLabel()
  54. }
  55.  
  56. func positionLegalMapLabel() {
  57. if self.mapView.subviews.count > 1 {
  58. let legalMapLabel = self.mapView.subviews[1]
  59.  
  60. legalMapLabel.frame.origin = CGPointMake(self.mapView.bounds.size.width - legalMapLabel.frame.size.width - 7, legalMapLabel.frame.origin.y)
  61. }
  62. }
Add Comment
Please, Sign In to add comment