Roger Zhang
Roger Zhang

Reputation: 11

How do I change UINavigationBar height programmatically?

How to change UINavigationBar height with code int iOS8 swift?

I've tried using:

UINavigationBar.resizableSnapshotViewFromRect

UINavigationBar.drawViewHierarchyInRect

UINavigationBar.frameForAlignmentRect

None of these seem to accomplish this.

Upvotes: 0

Views: 6195

Answers (1)

Dharmesh Kheni
Dharmesh Kheni

Reputation: 71852

Here is example for you:

import UIKit

class BaseViewConroller: UIViewController {
var navBar:UINavigationBar=UINavigationBar()

override func viewDidLoad() {
    super.viewDidLoad()
    setNavBarToTheView()
    // Do any additional setup after loading the view.
    self.title="test test"
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

func setNavBarToTheView()
{
    navBar.frame=CGRectMake(0, 0, 320, 50)  // Here you can set you Width and Height for your navBar
    navBar.backgroundColor=(UIColor .blackColor())
    self.view .addSubview(navBar)
}

}

Upvotes: 3

Related Questions