move navigationBar's left and right barButtonI

2019-08-22 06:44发布

I am trying to move my navigation bar's left and right barButtonItem's upwards vertically without any success. I can manage to move the title view up but using the same method for the barButtonItem's doesn't do anything.

The effect I'm trying to achieve is what is used on the Bookmarks page of safari:

enter image description here

I'm hoping to achieve this without any subclassing of the navigationBar so that I can maintain the translucency.

My approach was to add UIView's to the navigationBar directly in IB for the leftBarButtonItem, Title and rightBarButtonItem. This works fine for the title and I'm able to add the Title and segmentedControl. The problem is when I add the left and right barButtonItem's I am not able to move them vertically above my segmented control. I am using the following code to try to move the barButtonItem's vertically in viewDidLoad():

    self.navigationItem.rightBarButtonItem?.setBackgroundVerticalPositionAdjustment(-15, for: UIBarMetrics.defaultPrompt)

    self.navigationItem.rightBarButtonItem?.setBackgroundVerticalPositionAdjustment(-15, for: UIBarMetrics.compactPrompt)

0条回答
登录 后发表回答