How to adjust the vertical position of a button in a navigation bar?

I can adjust the height of my title in the navigation bar:

self.profileNavigationBar.setTitleVerticalPositionAdjustment(10, forBarMetrics: UIBarMetrics.Default) 

But I can’t adjust the button on the navigation bar to match the position of the title. enter image description here

Now the setup button is in an awkward position. I tried

  self.navigationItem.rightBarButtonItem?.setTitlePositionAdjustment(UIOffsetMake(20, 10), forBarMetrics: UIBarMetrics.Default) self.navigationItem.rightBarButtonItem?.setBackButtonBackgroundVerticalPositionAdjustment(10, forBarMetrics: UIBarMetrics.Default) self.navigationItem.rightBarButtonItem?.setBackButtonTitlePositionAdjustment(UIOffsetMake(20, 20), forBarMetrics: UIBarMetrics.Default) 

none of them work for me. Does anyone have any ideas? Many thanks!

+4
source share
3 answers

I kind of understand.

Select the button in the storyboard, configure the “Insert” tab in the “Attribute inspector”.

+2
source

Try adjusting the vertical position:

 navigationItem.rightBarButtonItem?.setBackgroundVerticalPositionAdjustment(10.0, for: .default) 
+2
source

I found a solution to this problem by setting in the Image Edge tabs in a custom button. I had a requirement in the application to increase the height of the navigation bar, and after increasing the height makes the problem RightBarButtonItem and leftBarButtonItem irregular.

Find the code below: -

 UIImage *image = [[UIImage imageNamed:@"searchbar.png"]; UIButton* searchbutton = [UIButton buttonWithType:UIButtonTypeCustom]; [searchbutton addTarget:self action:@selector(searchBar:) forControlEvents:UIControlEventTouchUpInside]; searchbutton.frame = CGRectMake(0,0,22, 22); [searchbutton setImage:image forState:UIControlStateNormal]; [searchbutton setImageEdgeInsets:UIEdgeInsetsMake(-50, 0,50, 0)]; // Make BarButton Item UIBarButtonItem *navItem = [[UIBarButtonItem alloc] initWithCustomView:searchbutton]; self.navigationItem.rightBarButtonItem = navItem; 
0
source

All Articles