Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

xcode

ios

swift

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

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

But I cannot adjust the button in the navigation bar to fit the title position. enter image description here

The setting button is at an awkward position now. 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 works for me. Anyone has ideas? Thanks a lot!

like image 886
sekaisan Avatar asked Sep 27 '22 01:09

sekaisan


2 Answers

I kind of figure it out.

Select the button in the storyboard, adjust the Edge Inset under Attributes Inspector.

like image 199
sekaisan Avatar answered Nov 15 '22 09:11

sekaisan


Try this to adjust the vertical position:

navigationItem.rightBarButtonItem?.setBackgroundVerticalPositionAdjustment(10.0, for: .default)
like image 21
odm Avatar answered Nov 15 '22 09:11

odm