Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
422 views
in Technique[技术] by (71.8m points)

ios - How can I change height of Navigation Bar - 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 ?

I tried this:

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

but nothing happens...

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!

enter image description here

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

UPDATE 8/3/20: I posted this in 2016. A number of people have stated this no longer works so please use at your own risk. I am not working in iOS at the moment so I do not have an update handy. Best of luck!

Here is one way to do it:

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)
    
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...