如何更改导航栏的高度 - Swift 3 [英] How can I change height of Navigation Bar - Swift 3

查看:38
本文介绍了如何更改导航栏的高度 - Swift 3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很确定这不是重复的,因为我查看了其他答案,它们都过时了,并且没有提供确切的答案.

I'm pretty sure this is not duplicate because I looked at other answers and they all outdated and do not provide exact answer.

我有导航控制器和几个视图控制器.我想让导航栏高一点,以便它适合我需要的文本大小.我怎样才能做到这一点 ?

I have Navigation Controller and several view controllers. I want to make Navigation Bar a bit taller so it would fit text size that I need. How can I do that ?

我试过了:

UINavigationBar.appearance().frame = CGRect(x: 0.0, y: 0.0, width: 320.0, height: 210.0) 

但是什么都没发生...

but nothing happens...

此外,我无法使用 Xcode 布局按钮向导航栏添加任何约束.

Also, I wasn't able to add any constraints to the Nav Bar using Xcode layout buttons.

希望有人能帮我解决这个问题.提前致谢!

Hope somebody can help me to fix this issue. Thanks in advance!

推荐答案

UPDATE 8/3/20:我在 2016 年发布了这个.很多人表示这不再有效,所以请自担风险使用.我目前不在 iOS 中工作,所以我手边没有更新.祝你好运!

这是一种方法:

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    let height: CGFloat = 50 //whatever height you want to add to the existing height
    let bounds = self.navigationController!.navigationBar.bounds
    self.navigationController?.navigationBar.frame = CGRect(x: 0, y: 0, width: bounds.width, height: bounds.height + height)
    
}

这篇关于如何更改导航栏的高度 - Swift 3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆