Reputation: 686
is there a way to move MKUserTrackingBarButtonItem when it is attached to the navigationItem.rightBarButtonItem? Right now it looks like this:
and I want it to look more like in the maps by Apple (edit: be closer to the edge):
Is there a way to do this? I've tried ImageInsets with no luck.
Edit: Here is the code in viewDidLoad
MKUserTrackingBarButtonItem *trackingButton = [[MKUserTrackingBarButtonItem alloc] initWithMapView:self.mapView.mapView];
trackingButton.imageInsets = UIEdgeInsetsMake( 0, -10, 0, 0 );
self.navigationItem.rightBarButtonItem = trackingButton;
Upvotes: 0
Views: 867
Reputation: 686
All right, I found a working solution based on accepted answer to this question: How to Edit Empty Spaces of Left, Right UIBarButtonItem in UINavigationBar [iOS 7]
So in my code it looks like this
UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
target:nil action:nil];
negativeSpacer.width = -7.5;
MKUserTrackingBarButtonItem *trackingButton = [[MKUserTrackingBarButtonItem alloc] initWithMapView:self.mapView.mapView];
[self.navigationItem setRightBarButtonItems:[NSArray arrayWithObjects:negativeSpacer, trackingButton, nil] animated:NO];
Although it doesn't work as expected for iPhone 6 Plus, it's best solution for now. Thanks everyone for their help.
Upvotes: 1
Reputation: 1521
button1.imageEdgeInsets = UIEdgeInsetsMake(-4, 0, 0, 0);
The answer here: Can I change the position of navigationbar item?
Beware, you change insets of the button that to be assigned to the rightBarButtonItem, not the rightBarButtonItem itself.
Upvotes: 1