Add space from the top for navigation title

2019-03-07 08:23发布

问题:

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: