IOS UITabBar 隐藏分割线

最新在仿照网易云做性皮肤, 希望做成的效果如下: 顶部没有分割线

这里写图片描述

自己的效果 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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值