最近项目上遇到了一个小问题,手机升级ios13之后,隐藏tabbar上面的横线失效了。然后Google了半天,从github的CYLTabBarController开源项目第#463issues找到了一个解决方法,完美。下面代码是ios13之前的隐藏方法:
[[UITabBar appearance] setBackgroundImage:[[UIImage alloc]init]];
[[UITabBar appearance] setShadowImage:[[UIImage alloc]init]];
[UITabBar appearance].backgroundColor = [UIColor whiteColor];//根据自己的情况设置
ios13之后隐藏方法为:
UITabBarAppearance *standardAppearance = [[UITabBarAppearance alloc] init];
standardAppearance.backgroundColor = [UIColor whiteColor];//根据自己的情况设置
standardAppearance.shadowColor = [UIColor clearColor];//也可以设置为白色或任何颜色
self.tabBar.standardAppearance = standardAppearance;
综合起来的代码为:
if (@available(iOS 13.0, *)) {
UITabBarAppearance *standardAppearance = [[UITabBarAppearance alloc] init];
standardAppearance.backgroundColor = [UIColor whiteColor];//根据自己的情况设置
standardAppearance.shadowColor = [UIColor clearColor];//也可以设置为白色或任何颜色
self.tabBar.standardAppearance = standardAppearance;
}else{
[[UITabBar appearance] setBackgroundImage:[[UIImage alloc]init]];
[[UITabBar appearance] setShadowImage:[[UIImage alloc]init]];
[UITabBar appearance].backgroundColor = [UIColor whiteColor];//根据自己的情况设置
}
网友评论