1,設(shè)置透明導(dǎo)航欄:
UINavigationBar *bar = self.navigationController.navigationBar;
[bar setShadowImage:[UIImage new]];
[bar setBackgroundImage:[UIImage new] forBarMetrics:(UIBarMetricsDefault)];
2,設(shè)置導(dǎo)航欄顏色(在設(shè)置透明后設(shè)置barTintColor無效):
盡管設(shè)置了透明度但是還是紅色礁蔗,沒有透明度效果
設(shè)置了圖片哪怕是空圖片[UIImage new],再去設(shè)置barTintColor就無效了
bar.barTintColor = [[UIColor redColor] colorWithAlphaComponent:0.2];
3,設(shè)置導(dǎo)航欄透明度甩卓,通過顏色生成圖片安券,設(shè)置背景圖片:
UINavigationBar *bar = self.navigationController.navigationBar;
UIColor *color = [[UIColor redColor] colorWithAlphaComponent: 0.5] ;
UIImage *image = [UIImage imageWithColor:color]; //通過顏色設(shè)置圖片
[bar setBackgroundImage:image forBarMetrics:(UIBarMetricsDefault)];
[bar setShadowImage:[UIImage new]]; //
4,設(shè)置了[bar setBackgroundImage:image forBarMetrics:(UIBarMetricsDefault)];再設(shè)置bar TintColor,那么barTintColor設(shè)置無效.
5, 顯示狀態(tài)欄本讥。
a,全局設(shè)置:
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
b,單個控制器設(shè)置(preferredStatusBarStyle不執(zhí)行的原因):
在控制器不在導(dǎo)航欄中時,plist中的View controller-based status bar appearance為YES的情況下, preferredStatusBarStyle才會執(zhí)行邮利。如果控制器在導(dǎo)航控制器中,那么控制器中實現(xiàn)preferredStatusBarStyle方法是無效的缺猛,因為導(dǎo)航控制器的導(dǎo)航欄本身就包含了狀態(tài)欄缨叫,導(dǎo)航控制器的狀態(tài)欄是通過UINavigationBar
的barStyle樣式來管理的,但前提是plist中的View controller-based status bar appearance為YES荔燎,通過設(shè)置:
//**前提plist中的View controller-based status bar appearance設(shè)置為YES**
//將status bar 文本顏色設(shè)置為白色
self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
//將status bar 文本顏色設(shè)置為黑色 ,默認就是黑色
self.navigationController.navigationBar.barStyle = UIBarStyleDefault;
6,全局設(shè)置:
全局設(shè)置在AppDelegate的didLaunch代理方法中執(zhí)行或者在自定義的CustomNavigationController的+initialize方法中執(zhí)行:
UINavigationBar *bar = [UINavigationBar appearance]; //用bar設(shè)置相應(yīng)屬性
*注意:在控制器中通過UINavigationBar bar = [UINavigationBar appearance];設(shè)置是無效的耻姥,應(yīng)該通過控制器的導(dǎo)航控制器的導(dǎo)航欄實例來修改具體的外觀屬性