導航欄顏色差異:
設置導航欄的 translucent 屬性為 NO
在單個界面設置
self.navigationController.navigationBar.translucent = NO;
如果是導航欄單獨設置
UINavigationBar * nav = [UINavigationBar appearance];
//設置背景色
nav.translucent = NO;
nav.barTintColor = ColorPrimary;
//設置字體顏色
NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
textAttrs[NSForegroundColorAttributeName] = White;
[nav setTitleTextAttributes:textAttrs];
[nav setTintColor:[UIColor whiteColor]];
對于導航欄和下面controller中間有一條線的情況,解決辦法是設置ShadowImage 屬性,但是這個屬性是設置那條線的顯示情況碧查,單獨設置是不起作用的舌镶,只有同時設置 self.navigationController.navigationBar 的背景色才能起作用阱扬,所以這里設置self.navigationController.navigationBar 的背景色為空白圖片幽污,并且把 ShadowImage設置為空白圖片 這樣就不會顯示出來那條黑線了框咙,如果想把那條黑線改為其他顏色只需要修改 ShadowImage的圖片就可以了
對于單個界面
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
//兩句代碼必須都有
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"無圖片"] forBarMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setShadowImage:[UIImage new]];
}
-(void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
//兩句代碼必須都有
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"無圖片"] forBarMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setShadowImage:nil];
}
如果是全局設置(在UINavigationBar的封裝類里面設置就可以了)
//兩句代碼必須都要有
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"無圖片"] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setShadowImage:[UIImage new]];