UITabBarController *tabVC = [[UITabBarController alloc] init];
UIImage *whiteImage = [self imageWithColor:[UIColor whiteColor]];
if (@available(iOS 13.0, *)) {
// 手动放一张白色底图遮住系统tabbar的顶部线条
// blankView颜色必须设置
UIView *blankView = [[UIView alloc] initWithFrame:CGRectMake(0, -0.5, UIScreen.mainScreen.bounds.size.width, 0.5)];
blankView.backgroundColor = UIColor.whiteColor;
[tabVC.tabBar addSubview:blankView];
} else {
[tabVC.tabBar setBackgroundImage:whiteImage];
[tabVC.tabBar setShadowImage:whiteImage];
}
// 通过颜色生成图片
- (UIImage *)imageWithColor:(UIColor *)color {
CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
网友评论