从顶部添加空间以获取导航标题 [英] Add space from the top for navigation title
问题描述
想要从顶部为导航标题购物清单提供额外空间。我该怎么做?不要在故事板中的导航项属性中看到选项。它接近日期,应用程序顶部的电池图标。
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.
附上截图。
< a href =https://i.stack.imgur.com/0JiZS.png =nofollow noreferrer>
尝试使用swift2进行以下代码无效
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
}
推荐答案
试试这段代码:在Swift 3中测试。
Try this code: Tested in Swift 3.
注意:方法1仅适用,如果您的VC嵌入了navigationController。在您的情况下,您只使用navigationBar来显示title.So,请使用方法2.
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.
方法1:
navigationController?.navigationBar.setTitleVerticalPositionAdjustment(5, for: UIBarMetrics.default) // set any number you want between -20 to 15
方法2:
navigationBar.setTitleVerticalPositionAdjustment(10, for: UIBarMetrics.default) // navigationBar is the name of your navBar..
输出:
这篇关于从顶部添加空间以获取导航标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!