美文网首页
iOS13 UITabbar 隐藏顶部分割线

iOS13 UITabbar 隐藏顶部分割线

作者: 你不诚实啊 | 来源:发表于2019-11-06 15:47 被阅读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;
}

相关文章

网友评论

      本文标题:iOS13 UITabbar 隐藏顶部分割线

      本文链接:https://www.haomeiwen.com/subject/lhbubctx.html