Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing the height of the Navigation bar iOS Swift

I am trying to change the height of there navigation bar for my app. Currently the height is fixed to 44. I can change the width from Xcode but not the height.

I have no idea how to change this. Very new to iOS development.

Can anyone please help?

like image 964
Skywalker Avatar asked Aug 21 '15 14:08

Skywalker


2 Answers

simply dragged and dropped it on my view

In that case, the simplest way is with constraints. Just give it a height constraint (along with the other constraints that position it). No code required! Here's an example:

enter image description here

That was achieved with no code at all. It's all done with constraints:

enter image description here

We are pinned to the top and sides of the superview, along with height constraint of 100.

like image 112
matt Avatar answered Nov 15 '22 18:11

matt


Try this :

import UIKit

class YourViewController : UIViewController {

    var navBar: UINavigationBar = UINavigationBar()

    override func viewDidLoad() {
        super.viewDidLoad()
        self.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() {
        self.navBar.frame = CGRectMake(0, 0, 320, 50)  // Here you can set you Width and Height for your navBar
        self.navBar.backgroundColor = (UIColor.blackColor())
        self.view.addSubview(navBar)
    }
}
like image 20
iAnurag Avatar answered Nov 15 '22 18:11

iAnurag