隐藏的最常见的操作,置其为透明🤣
在TabBarVC里
- (void)viewDidLoad {
[super viewDidLoad];
YTTabBar *tabBar = [[YTTabBar alloc] init];
tabBar.tbDelagete = self;
[self setValue:tabBar forKeyPath:@"tabBar"];
UIImage *bgImg = [UIImage imageWithColor:[UIColor clearColor] size:CGSizeMake(SCREEN_Width, TabBarHeight)];
[self.tabBar setBackgroundImage:bgImg];
[self.tabBar setShadowImage:bgImg];
}
修改分割线颜色
点xcode的Debug View Hierarchy可以看到,tabBar上有一条细线,其实就是一个超出父视图0.5像素的UIImageView。
那么,我们就可以置空tabbar的背景图和阴影,插入一个View,设成自己需要的颜色。
[self.tabBar setBackgroundImage:[UIImage new]];
[self.tabBar setShadowImage:[UIImage new]];
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, -0.5, SCREEN_Width, 0.5)];
view.backgroundColor = HEXCOLOR(0xf5f5f5);
[[UITabBar appearance] insertSubview:view atIndex:0];
达成目标😊。
给UIImage加的Category里
+ (UIImage *)imageWithColor:(UIColor *)color size:(CGSize)size{
if (size.width == 0 || size.height == 0) {
size = CGSizeMake(1, 1);
}
CGRect rect = CGRectMake(0, 0, size.width, size.height);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context,color.CGColor);
CGContextFillRect(context, rect);
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}