Add space from the top for navigation title

我是研究僧i 提交于 2019-12-03 00:37:00

问题


Want to give additional space from the top for navigation title shopping list. How can I do it? Dont see a option to do it in the properties of navigation item in the story board. Its close to the date, battery icon in the top of the app.

Attached the screenshot.

Tried the below code its not working using swift2

   override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
               navigationController?.navigationBar.setTitleVerticalPositionAdjustment(15,forBarMetrics: UIBarMetrics.Default) // set any number you want between -20 to 15


    }

回答1:


Try this code: Tested in Swift 3.

Note: Method 1 works only, If your VC embedded with navigationController.In your case you only using navigationBar to show title.So, use method 2.

Method 1:

 navigationController?.navigationBar.setTitleVerticalPositionAdjustment(5, for: UIBarMetrics.default) // set any number you want between -20 to 15

Method 2:

 navigationBar.setTitleVerticalPositionAdjustment(10, for: UIBarMetrics.default) // navigationBar is the name of your navBar..

Output:



来源:https://stackoverflow.com/questions/40437255/add-space-from-the-top-for-navigation-title

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