move navigationBar's left and right barButtonItem's vertically upwards

放肆的年华 提交于 2020-01-17 07:25:52

问题


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:

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)

来源:https://stackoverflow.com/questions/44181264/move-navigationbars-left-and-right-barbuttonitems-vertically-upwards

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!