I am coding one Location based App by Swift.
I make my MapView can show Compass, but I would like to change the compass location from the right-up corner to the left-down corner.
Does any expert know how to move it?
Thank you in advanced.
You can do this by setting the compass visibility to false and then adding a new compass
mapView.showsCompass = false
let compassBtn = MKCompassButton(mapView:mapView)
compassBtn.frame.origin = CGPoint(x: self.view.frame.maxX - 40, y: 20)
compassBtn.compassVisibility = .adaptive
view.addSubview(compassBtn)
You can use adaptive visibility so your new compass will behave like the original one.
You can try to change this:
mapView.layoutMargins
Or subclass the MKMapView component:
import MapKit
class MyMapView: MKMapView {
override func layoutSubviews() {
super.layoutSubviews()
if let compassView = self.subviews.filter({ $0.isKindOfClass(NSClassFromString("MKCompassView")!) }).first {
compassView.frame = CGRectMake(15, 30, 36, 36)
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With