iOS 消除Tabbar 顶部线条

没去掉线条之前:

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
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容