默认状态栏高度: 20; 默认导航栏高度: 44;
默认导航栏的subviews,包括title,items,他们的位置都不可调。所以只能通过navigationBar添加自定义的subviews。
1. 自定义背景及高度:
1.1使状态栏与导航栏保持一致:self.navigationController?.navigationBar.setBackgroungImage(...),然后在其下方添加一个UIImageView到想要的高度:navigationBar.addSubview,setBackgroungImage会连同状态栏一起set。
这时根据导航栏背景的颜色,可能需要调整状态栏字体颜色: 在AppDelegate->didFinishLaunching里面,application.setStatusBarStyle.LightContent(...)
1.2或者不set背景直接覆盖UIImageView,那么不会改变状态栏。
1.3半透明导航栏/状态栏:1.1 的图片或color设为半透明,然后self.view添加图片,图片rect的Y值设为0,则状态栏也改变,设为20则从导航栏之后开始。
结果可以为:
2. 自定义title:
加label,然后别忘了在每个VC的viewWillAppear里面设定VC的Title。
3. 自定义items:
3.1 左边的:var naviBtnBack =UIButton(...),添加target等等,然后self.navigationItem.leftBarButtonItem = UIBarButtonItem(customView: naviBtnBack),相当于覆盖了返回按钮。
target函数里面:self.navigationController?.popToRootViewControllerAnimated(true)
3.2 右边的:var naviBtnNew =UIButton(...),self. navigationController?. navigationBar. addSubview (naviBtnNew)。
var newViewController =NewViewController();设置newViewController属性、传值;
self.navigationController?.pushViewController(newViewController, animated:true)
最好在viewWillAppear里面设置导航栏属性;每次push一个newVC的时候要删除右边的button:naviBtnNew.removefromsuperview;左边的button不用remove。