简体   繁体   中英

I got a bug when set NavigationBar translucent

When I set NavigationBar to translucent, I expect that the NavigationBar will not has a shadow line under it, and StatusBar has the same background of the view's background 结果是我所期望的

I code like this:

[self.navigationController.navigationBar setTranslucent:YES];
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"translucent_image"] forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [UIImage new];

They work perfectly on 5.5 inch iPhone like iPhone6 Plus and iPhone 6s Plus, But when run on the smaller iPhones like iPhone 6s and iPhone 5s, I get a bug like problem, The StatusBar turn into black! They are the same code on iOS 8.2, iOS 8.3 and iOS 9.2, The only difference is the screen! 在iPhone6s,iPhone 6和iPhone 5s上运行时为黑色StatusBar

I try to change the BarMetrics from UIBarMetricsDefault to UIBarMetricsCompact or UIBarMetricsDefaultPrompt to fix this problem, finally the StatusBar work well but the shadow line come out in all iPhones!

[self.navigationController.navigationBar setTranslucent:YES];
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"translucent_image"] forBarMetrics: UIBarMetricsCompact];
self.navigationController.navigationBar.shadowImage = [UIImage new];

阴影线出来

so strange! is this a bug of iOS?

Try changing your code to

[self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
[self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc]init] forBarMetrics:UIBarMetricsDefault];

This works for me (ie I don't get the shadow)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM