做项目过程中遇到要去掉导航栏下面的一条黑线,从网上找到的一个方法
默认UINavigationbar样式
准备用于替换的背景
替换后的效果
if ([self.navigationController.navigationBar respondsToSelector:@selector( setBackgroundImage:forBarMetrics:)]){
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"top_bg"] forBarMetrics:UIBarMetricsDefault];
}
在ios7中,执行以上代码替换navigationBar的背景图片后,出现一条很明显的黑线,请问各位大哥,如何去除黑线?
-----------------------------------------------------------------------------------
等了一个多小时没人回答,好难过!
还好我自己解决了!
方法如下:
if ([self.navigationController.navigationBar respondsToSelector:@selector( setBackgroundImage:forBarMetrics:)]){
NSArray *list=self.navigationController.navigationBar.subviews;
for (id obj in list) {
if ([obj isKindOfClass:[UIImageView class]]) {
UIImageView *imageView=(UIImageView *)obj;
imageView.hidden=YES;
}
}
UIImageView *imageView=[[UIImageView alloc] initWithFrame:CGRectMake(0, -20, 420, 64)];
imageView.image=[UIImage imageNamed:@"top_bg"];
[self.navigationController.navigationBar addSubview:imageView];
[self.navigationController.navigationBar sendSubviewToBack:imageView];
}