美文网首页
iOS移除TabBar上影线

iOS移除TabBar上影线

作者: 忆一曲肝肠断 | 来源:发表于2020-04-29 21:08 被阅读0次

iOS移除TabBar上影线,有时候我们根据UI需求,为了美观要把原生的TabBar上影线去掉,也就是TabBar上面那根线,废话不多说,上代码
其原理就是空白替换。

- (void)removeTabBarTopLine {
    
    CGRect rect = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 0.5);

    UIGraphicsBeginImageContext(rect.size);

    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextSetFillColorWithColor(context, [[UIColor whiteColor] CGColor]);

    CGContextFillRect(context, rect);

    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    [self.tabBar setBackgroundImage:img];

    [self.tabBar setShadowImage:img];
    
}

还有一种方法也是大差不差,还是废话不多说,上代码。

 UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, -0.5, SCREENWIDTH, 0.5)];
    view.backgroundColor = [UIColor grayColor];
    view.alpha = 0.1;
    [[UITabBar appearance] insertSubview:view atIndex:0];
    [[UITabBar appearance] setBackgroundColor:[UIColor whiteColor]];
    [UITabBar appearance].translucent = NO;

具体情况具体对待。

是不是很简单,每天更新小功能,记得点赞加关注哦

相关文章

网友评论

      本文标题:iOS移除TabBar上影线

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