美文网首页
iOS 消除Tabbar 顶部线条

iOS 消除Tabbar 顶部线条

作者: Forever3389 | 来源:发表于2021-10-23 13:46 被阅读0次

    没去掉线条之前:

    image.png

    代码处理

    @interface STLAnimationTabBar : UITabBar
    @property (nonatomic, strong) NSMutableArray    *animViewArray;
    @end
    
      @implementation STLAnimationTabBar
       - (void)layoutSubviews {
        [super layoutSubviews];
        ///消除TabBar顶部细线
        [self hideTabBarTopLine];
      }
    

    调用方法

    - (void)hideTabBarTopLine {
        for (UIView *tempView in self.subviews) {
            if (![tempView isKindOfClass:[NSClassFromString(@"_UIBarBackground") class]]) continue;
            
            for (UIView *tempSubView in tempView.subviews) {
                if (![tempSubView isKindOfClass:[NSClassFromString(@"_UIBarBackgroundShadowView") class]]) continue;
                
                for (UIView *thirdSubView in tempSubView.subviews) {
                    if (![thirdSubView isKindOfClass:[NSClassFromString(@"_UIBarBackgroundShadowContentImageView") class]]) continue;
                    
                    if (thirdSubView.frame.size.height < 1.0) {
                        thirdSubView.backgroundColor = [UIColor clearColor];
                        thirdSubView.layer.backgroundColor = [UIColor clearColor].CGColor;
                    }
                    return;
                }
            }
        }
    }
    

    Controller调用 ----STLTabBarController

    ///自定义Tabbar为了获取icon的父视图
    - (void)setupTabBarAnimation {
        STLAnimationTabBar *appTabBar = [[STLAnimationTabBar alloc] initWithFrame:self.tabBar.bounds];
        [self setValue:appTabBar forKeyPath:@"tabBar"];
    }
    

    去掉之后如下图

    image.png

    相关文章

      网友评论

          本文标题:iOS 消除Tabbar 顶部线条

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