1,设置透明导航栏:
UINavigationBar *bar = self.navigationController.navigationBar;
[bar setShadowImage:[UIImage new]];
[bar setBackgroundImage:[UIImage new] forBarMetrics:(UIBarMetricsDefault)];
2,设置导航栏颜色(在设置透明后设置barTintColor无效):
尽管设置了透明度但是还是红色,没有透明度效果
设置了图片哪怕是空图片[UIImage new],再去设置barTintColor就无效了
bar.barTintColor = [[UIColor redColor] colorWithAlphaComponent:0.2];
3,设置导航栏透明度,通过颜色生成图片,设置背景图片:
UINavigationBar *bar = self.navigationController.navigationBar;
UIColor *color = [[UIColor redColor] colorWithAlphaComponent: 0.5] ;
UIImage *image = [UIImage imageWithColor:color]; //通过颜色设置图片
[bar setBackgroundImage:image forBarMetrics:(UIBarMetricsDefault)];
[bar setShadowImage:[UIImage new]]; //
4,设置了[bar setBackgroundImage:image forBarMetrics:(UIBarMetricsDefault)];再设置bar TintColor,那么barTintColor设置无效.
5, 显示状态栏。
a,全局设置:
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
b,单个控制器设置(preferredStatusBarStyle不执行的原因):
在控制器不在导航栏中时,plist中的View controller-based status bar appearance为YES的情况下, preferredStatusBarStyle才会执行。如果控制器在导航控制器中,那么控制器中实现preferredStatusBarStyle方法是无效的,因为导航控制器的导航栏本身就包含了状态栏,导航控制器的状态栏是通过UINavigationBar
的barStyle样式来管理的,但前提是plist中的View controller-based status bar appearance为YES,通过设置:
//**前提plist中的View controller-based status bar appearance设置为YES**
//将status bar 文本颜色设置为白色
self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
//将status bar 文本颜色设置为黑色 ,默认就是黑色
self.navigationController.navigationBar.barStyle = UIBarStyleDefault;
6,全局设置:
全局设置在AppDelegate的didLaunch代理方法中执行或者在自定义的CustomNavigationController的+initialize方法中执行:
UINavigationBar *bar = [UINavigationBar appearance]; //用bar设置相应属性
*注意:在控制器中通过UINavigationBar bar = [UINavigationBar appearance];设置是无效的,应该通过控制器的导航控制器的导航栏实例来修改具体的外观属性
网友评论