IOS 在IOS6中设置navigationBar背景图片 会有一条 黑色阴影 --- 解决方案
陈功
2023-12-01
//给navigationBar设置背景图片
if ([self.navigationController.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)]) {
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"nav_bg.png"]
forBarMetrics:UIBarMetricsDefault];
}
self.navigationController.navigationBar.layer.contents = (id)[UIImage imageNamed:@"nav_bg.png"].CGImage;
解决方案 1:
[self.navigationController.navigationBar.layer setMasksToBounds:YES]; // 剪切掉多余的背景
解决方案 2:
self.navigationController.navigationBar.clipsToBounds = YES;
解决方案 3:
CustomNavBar *navBar = (CustomNavBar *)self.navigationController.navigationBar;
[navBar setBackgroundImage:[UIImage imageNamed:@"navigation_bar_gray.png"] forBarMetrics:UIBarMetricsDefault];
navBar.shadowImage = [[UIImage alloc]init]; // this is what acctually removed the shadow under navigation bar