最新在仿照网易云做性皮肤, 希望做成的效果如下: 顶部没有分割线
自己的效果 setBackgroundImage 发现顶部出现 烦人的分割线.
在 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];
这样就达到了效果 :
烦人的分割线消失了
本文参考了以下文章 :
https://stackoverflow.com/questions/14371343/ios-uitabbar-remove-top-shadow-gradient-line
http://www.jianshu.com/p/be8a258526d1