//必须设置为UIBarStyleBlack 否则毛玻璃效果不是黑色的
[self.navigationBar setBarStyle:UIBarStyleBlack];
[self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
UIView *bgView = [[UIView alloc] init];
bgView.frame = ({
CGRect frame = self.navigationBar.bounds;
frame.size.height += 20;
frame.origin.y -= 20;
frame;
});
CAGradientLayer *gradientLayer = [[CAGradientLayer alloc] init];
gradientLayer.frame = bgView.bounds;
[UIColor colorWithRed:4/255.0 green:0 blue:18/255.0 alpha:0.76];
gradientLayer.colors = @[(__bridge id)[UIColor colorWithRed:4/255.0 green:0 blue:18/255.0 alpha:0.76].CGColor,(__bridge id)[UIColor colorWithRed:4/255.0 green:0 blue:18/255.0 alpha:0.28].CGColor];
gradientLayer.startPoint = CGPointMake(0, 0);
gradientLayer.endPoint = CGPointMake(0, 1.0);
[bgView.layer addSublayer:gradientLayer];
bgView.userInteractionEnabled = NO;
//保证bgView 在最底部
bgView.layer.zPosition = -1;
[self.navigationBar addSubview:bgView];
[self.navigationBar sendSubviewToBack:bgView];