修改导航透明度最简单的方法就导航设置 self.navigationController.navigationBar.translucent = YES; 同时在添加 一个透明图片,
如果需求总是更改的话,要总换图片,作为一个懒惰的程序员,不如直接用代码创建个可以改变色值的图片,这样更方便,苹果的程序员就是这么写得哦
//opacity 修改透明度, CGContextSetRGBFillColor(context, 1, 142, 107, opacity); 用来修改色值
- (void)applyTransparentBackgroundToTheNavigationBar:(CGFloat)opacity
{
UIImage *transparentBackground;
UIGraphicsBeginImageContextWithOptions(CGSizeMake(1, 1), NO, self.navigationController.navigationBar.layer.contentsScale);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetRGBFillColor(context, 1, 142, 107, opacity);
UIRectFill(CGRectMake(0, 0, 1, 1));
transparentBackground = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
id navigationBarAppearance = self.navigationController.navigationBar;
[navigationBarAppearance setBackgroundImage:transparentBackground forBarMetrics:UIBarMetricsDefault];
}