美文网首页
简单透明导航栏

简单透明导航栏

作者: 曉風滿月 | 来源:发表于2017-03-24 20:15 被阅读0次

参考简书

代码.h

#import <UIKit/UIKit.h>

@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

相关文章

网友评论

      本文标题:简单透明导航栏

      本文链接:https://www.haomeiwen.com/subject/pgxqottx.html