IOS UITabBar 隐藏分割线 曾经终败给现在 2022-06-03 04:23 267阅读 0赞 最新在仿照网易云做性皮肤, 希望做成的效果如下: 顶部没有分割线 ![这里写图片描述][SouthEast] 自己的效果 setBackgroundImage 发现顶部出现 烦人的分割线. ![这里写图片描述][SouthEast 1] 在 [https://stackoverflow.com/questions/14371343/ios-uitabbar-remove-top-shadow-gradient-line][https_stackoverflow.com_questions_14371343_ios-uitabbar-remove-top-shadow-gradient-line] 和国内的一些论坛上搜索,基本就是下方的答案. [[UITabBar appearance] setBackgroundImage:[[UIImage alloc] init]]; [[UITabBar appearance] setShadowImage:[[UIImage alloc] init]]; 但是这样会我的背景变成了白色. 顶部分割线连同背景一起消失了.后来想了一个办法.索性直接隐藏掉背景.自己添加一个 UIImageView 作为背景.代码如下: cm2\_btm\_bg 为上图中橙色的背景. [self.tabBar setBackgroundImage:[[UIImage alloc] init]]; UIImageView *image = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"cm2_btm_bg"]]; image.contentMode = UIViewContentModeScaleAspectFill ; image.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, self.tabBar.frame.size.height); [self.tabBar insertSubview:image atIndex:0 ]; //或者 [[UITabBar appearance]insertSubview:image atIndex:0]; 这样就达到了效果 : ![这里写图片描述][SouthEast 2] 烦人的分割线消失了 本文参考了以下文章 : [https://stackoverflow.com/questions/14371343/ios-uitabbar-remove-top-shadow-gradient-line][https_stackoverflow.com_questions_14371343_ios-uitabbar-remove-top-shadow-gradient-line] [http://www.jianshu.com/p/be8a258526d1][http_www.jianshu.com_p_be8a258526d1] [SouthEast]: /images/20220603/5bd31bcdd5044beeb0c4f99efccd1a7f.png [SouthEast 1]: /images/20220603/6730ab32676e4d809006718198a1e1fc.png [https_stackoverflow.com_questions_14371343_ios-uitabbar-remove-top-shadow-gradient-line]: https://stackoverflow.com/questions/14371343/ios-uitabbar-remove-top-shadow-gradient-line [SouthEast 2]: /images/20220603/2ce3b570b4dd41c4ad75c367ffbd6187.png [http_www.jianshu.com_p_be8a258526d1]: http://www.jianshu.com/p/be8a258526d1
还没有评论,来说两句吧...