美文网首页iOS Developer
运用递归算法隐藏导航栏黑线,并替换

运用递归算法隐藏导航栏黑线,并替换

作者: NSLogGPX | 来源:发表于2016-11-22 20:06 被阅读31次

    下面两段代码都放在UINavigationController 或者自定义的UINavigationController

    - (void)viewWillAppear:(BOOL)animated{
        [super viewWillAppear:animated];
        // 运用递归影藏自带的黑线
        [self hideBorderInView:self.navigationBar];
        // 需要设置成的样子
        if (!_navLineV) {
            _navLineV = [[UIView alloc]initWithFrame:CGRectMake(0, 44, kScreen_Width, 1.0/ [UIScreen mainScreen].scale)];
            _navLineV.backgroundColor = kColorCCC;
            _navLineV.backgroundColor = [UIColor redColor];
            [self.navigationBar addSubview:_navLineV];
        }
    }
    
    // 递归 遍历view的subViews 直至隐藏
    - (void)hideBorderInView:(UIView *)view{
    
        if ([view isKindOfClass:[UIImageView class]]
            && view.frame.size.height <= 1) {
            view.hidden = YES;
        }
        for (UIView *subView in view.subviews) {
            [self hideBorderInView:subView];
        }
    }
    
    • 设置后的效果
    • imageimage

    相关文章

      网友评论

        本文标题:运用递归算法隐藏导航栏黑线,并替换

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