/*1. 設置navigationBar是否半透明效果,默認是 =YES 的,
我們把它變成NO就可以設置navigationBar的顏色為不透明的顏色*/
self.navigationController.navigationBar.translucent = NO; //不透明
//2. 這個顏色設置默認包含了狀態(tài)欄
self.navigationController.navigationBar.barTintColor = [UIColor redColor];
//3. 這個屬性設置的是item的渲染色
self.navigationController.navigationBar.tintColor = [UIColor grayColor];
//4. 設置導航欄title字體顏色
//[注意:] 這個設置只能在當前界面生效,如果是在push前設置,則沒有效果
//另外:push的過去的界面title字體顏色是根據當前界面顏色確定的
self.title = @"測試";
self.navigationController.navigationBar.titleTextAttributes =
@{NSForegroundColorAttributeName : [UIColor blueColor]};
下面是和跳轉相關的屬性
HotModel *model = self.dataArr[indexPath.row];
DetailViewController *detailCon = [[DetailViewController alloc] init];
detailCon.detailId = model.id;
//改變跳轉后的item屬性,比如說title,color之類的
UIBarButtonItem *item = [[UIBarButtonItem alloc] init];
self.navigationItem.backBarButtonItem = item;
//改變item的渲染色
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
//改變DetailCon的返回鍵item的標題
item.title = @"Back";
[self.navigationController pushViewController:detailCon animated:YES];
然后是效果圖對比
navBar1.png
navBar2.png