I have the following code to configure the display of UIBarButtonItem (locationButton):
UIButton *locationButtonAux = [UIButton buttonWithType:UIButtonTypeCustom]; [locationButtonAux setFrame:CGRectMake(0, 0, LOCATION_BUTTON_WIDTH, LOCATION_BUTTON_HEIGHT)]; [locationButtonAux setBackgroundImage:[UIImage imageNamed:@"location_button.png"] forState:UIControlStateNormal]; [locationButtonAux setBackgroundImage:[UIImage imageNamed:@"location_button.png"] forState:UIControlStateHighlighted]; [locationButtonAux addTarget:self action:@selector(userLocation) forControlEvents:UIControlEventTouchUpInside]; UIBarButtonItem *locationButton = [[UIBarButtonItem alloc] initWithCustomView:locationButtonAux]; UIBarButtonItem * item = [[UIBarButtonItem alloc] initWithTitle:@"title" style:UIBarButtonItemStyleDone target:nil action:@selector(someMssage)]; [locationButton setBackgroundVerticalPositionAdjustment:-20.0 forBarMetrics:UIBarMetricsDefault]; self.navigationItem.rightBarButtonItem = locationButton;
And I want to change the position of this button in the NavigationBar, because my NavigationBar is higher than usual (configured using Appeareance).
I am using the setBackgroundVerticalPositionAdjustment method, as you can see in the code, for this. But it doesnβt work with my UIBarButtonItem at all, no matter what offset I put there, the button is always displayed close to the bottom of the panel (snapshot). BUT, if I use the usual UIBarButtonItem with the usual style (the one that I called the button), I can see how the button position will be changed to an offset of -20. Very strange ... Any ideas?
Thanks!

source share