在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;
}