UITabbar及UINavigationBar上的黑线去除

在tips发表后,有网友回复直接一句代码去除黑线,过去还真没试过,受教:

[UITabBar appearance].clipsToBounds = YES;
[UINavigationBar appearance].clipsToBounds = YES;

上面的方法固然漂亮,但对于有些特殊要求的,比如:TabBar中间凸起、以及类似简书的导航栏头像缩放伸缩等,就不适用了:GitHub下载地址

效果图

去除tabbar上的黑线一般做法是在tabbar上覆盖覆盖一张背景图片,具体代码,在自定义Tabbar里的didload方法里添加,如下代码

- (void)viewDidLoad
{
  [super viewDidLoad];

  //设置tabbar背景颜色
  [[UITabBar appearance] setBackgroundColor:[UIColor whiteColor]];
  [[UITabBar appearance] setBarTintColor:[UIColor whiteColor]];
  [[UITabBar appearance] setTintColor:ButtonColor];
  [[UITabBar appearance] setBackgroundImage:[UIImage imageNamed:@"tabbarImage.png"]];
  // [UITabBar appearance].clipsToBounds = YES; // 添加的图片大小不匹配的话,加上此句,屏蔽掉tabbar多余部分 
  [[UITabBar appearance] setShadowImage:[UIImage imageNamed:@"tabbarImage.png"]];
    }

导航NavigationBar的黑线条,去除相对容易,如果需要全局的,只需,在AppDelegate的didFinishLaunchingWithOptions方法中添加两行代码:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
    {
      [[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
      [[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];
     return YES;
    }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容