方法一:
[self .navigationController.navigationBar setBackgroundImage:[UIImage imageWithColor:XBColor_Blue] forBarMetrics:UIBarMetricsDefault] ;
[self.navigationController.navigationBar setShadowImage:[UIImage new]];
方法二:
- (void)setNeedsNavigationBackground:(CGFloat)alpha {
// 導航欄背景透明度設置
UIView *barBackgroundView = [[self.navigationBar subviews] objectAtIndex:0];// _UIBarBackground
UIImageView *backgroundImageView = [[barBackgroundView subviews] objectAtIndex:0];// UIImageView
if (self.navigationBar.isTranslucent) {
if (backgroundImageView != nil && backgroundImageView.image != nil) {
barBackgroundView.alpha = alpha;
} else {
UIView *backgroundEffectView = [[barBackgroundView subviews] objectAtIndex:1];// UIVisualEffectView
if (backgroundEffectView != nil) {
backgroundEffectView.alpha = alpha;
}
}
} else {
barBackgroundView.alpha = alpha;
}
}
// 對導航欄下面那條線做處理
self.navigationBar.clipsToBounds = alpha == 0.0;