1.設置導航欄為不透明
self.navigationController.navigationBar.translucent = NO;
UIView *redView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 40)];
redView.backgroundColor = [UIColor redColor];
[self.view addSubview:redView];
導航欄不透明.png
2.設置導航欄為半透明 [系統默認就是半透明的]
注意:iOS 導航欄如果設置為半透明,則其透明度為90%.也就是說,如果設置self.navigationController.navigationBar.barTintColor =[UIColor colorWithRed:1 green:0 blue:0 alpha:1];
,真正顯示到界面上的顏色是有90%透明的
self.navigationController.navigationBar.translucent = YES;
導航欄半透明.png
3.設置導航欄的背景顏色不會影響半透明translucent
這個屬性
4.隱藏導航欄
只要隱藏了導航欄后,不管translucent
這個屬性的值是ture或者false都會是下圖效果
隱藏導航欄.png
結果說明
如果設置了導航欄的translucent = YES
這時在添加子視圖的坐標原點相對屏幕坐標是(0,0).如果設置了translucent = NO
這時添加子視圖的坐標原點相對屏幕坐標就是(0, 64).
坐標說明.png
二.加載xib到導航控制器中
xib.png
這里的xib是一個控制器所對應的view,使用導航控制器push到這個控制器的時候,得到以下兩種情況.
1.導航欄半透明
半透明.png
2.導航欄不透明
Paste_Image.png