1.設(shè)置導(dǎo)航條顏色
注意:在這里設(shè)置透明度是沒有效果的
self.navigationController.navigationBar.barTintColor = [[UIColor yellowColor] colorWithAlphaComponent:0.3];
2.設(shè)置導(dǎo)航條圖片
***注意:1.圖片是會(huì)被平鋪的。 2.設(shè)置了圖片,顏色會(huì)被覆蓋。 ***
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"image01"] forBarMetrics:UIBarMetricsDefault];
3.設(shè)置導(dǎo)航條毛玻璃效果
//根據(jù)導(dǎo)航欄的結(jié)構(gòu)層次來實(shí)現(xiàn)
[[[self.navigationController.navigationBar subviews] objectAtIndex:0] setAlpha:0.5];
4.設(shè)置導(dǎo)航欄透明
[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
//去掉導(dǎo)航欄底部的黑線
self.navigationController.navigationBar.shadowImage = [UIImage new];
5.導(dǎo)航條的隱藏/顯示
//隱藏
self.navigationController.navigationBar.hidden = YES;
//顯示
self.navigationController.navigationBar.hidden = NO;
6.設(shè)置原點(diǎn)
屏幕原點(diǎn)一般會(huì)在屏幕的左上角,但是有時(shí)會(huì)在導(dǎo)航欄的左下角,向下偏移64個(gè)單位,這是因?yàn)樽詣?dòng)布局的原因
self.edgesForExtendedLayout = 0;
總結(jié):
1.導(dǎo)航欄默認(rèn)有過渡效果和毛玻璃效果,但是如果設(shè)置了背景顏色、圖片后,毛玻璃效果就會(huì)消失。
2.在一個(gè)控制器了設(shè)置了導(dǎo)航條了樣式,那么所有的導(dǎo)航條樣式都會(huì)改變,所以如果想要不同的效果,就要在視圖的顯示了消失代碼里在單獨(dú)設(shè)置回來。
3.有時(shí)一些復(fù)雜的效果需要可以讓導(dǎo)航欄隱藏,然后用UIView模擬導(dǎo)航欄。