How do I change UINavigationBar height programmatically?

风流意气都作罢 提交于 2019-12-08 11:28:19

问题


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.


回答1:


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

}


来源:https://stackoverflow.com/questions/26857050/how-do-i-change-uinavigationbar-height-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!