iOS 消除Tabbar 顶部线条
2021-10-23 本文已影响0人
Forever3389
没去掉线条之前:
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"];
}