如何以编程方式更改UINavigationBar高度?

时间:2014-11-11 03:35:21

标签: ios swift uinavigationbar

如何使用代码int iOS8 swift更改UINavigationBar高度?

我尝试过使用:

UINavigationBar.resizableSnapshotViewFromRect

UINavigationBar.drawViewHierarchyInRect

UINavigationBar.frameForAlignmentRect

这些似乎都没有实现这一目标。

1 个答案:

答案 0 :(得分:3)

以下是您的示例:

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

}