iOS13 UITabbar 隐藏顶部分割线

2019-11-06  本文已影响0人  你不诚实啊
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;
}
上一篇下一篇

猜你喜欢

热点阅读