简单透明导航栏

参考

代码.h

#import 

@interface UINavigationBar (Gradient)
- (void)setBGColor:(UIColor *)color;
- (void)setClearColor;
@end

代码.m

#import "UINavigationBar+Gradient.h"

@implementation UINavigationBar (Gradient)
- (void)setBGColor:(UIColor *)color {
    //去掉细线
    [self setShadowImage:[UIImage new]];
    [self setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
//    self.maskView addSubview:<#(nonnull UIView *)#>
    UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height + 20)];
    bgView.backgroundColor = color;
    [self.subviews.firstObject insertSubview:bgView atIndex:0];
//    [self.subviews ];
}
- (void)setClearColor {
    [self setBGColor:[UIColor clearColor]];
}
@end

你可能感兴趣的:(简单透明导航栏)