默认情况下会有这条线
第一种方法:
1 UINavigationBar *navigationBar = self.navigationController.navigationBar; 2 // white.png图片自己下载个纯白色的色块,或者自己ps做一个 3 [navigationBar setBackgroundImage:[UIImage imageNamed:@"white.png"] 4 forBarPosition:UIBarPositionAny 5 barMetrics:UIBarMetricsDefault]; 6 [navigationBar setShadowImage:[UIImage new]];
运行后效果如下(此处原有的灰色背景色会被white.png代替):
PS:这是唯一一个隐藏这条线的官方用法,但是有一个缺陷-删除了translucency(半透明)
第二种方法:
1)声明UIImageView变量,存储底部横线
1 @implementation MyViewController { 2 UIImageView *navBarHairlineImageView; 3 }
2)在viewDidLoad中加入:
1 navBarHairlineImageView = [self findHairlineImageViewUnder:navigationBar];
3)实现找出底部横线的函数
1 - (UIImageView *)findHairlineImageViewUnder:(UIView *)view { 2 if ([view isKindOfClass:UIImageView.class] && view.bounds.size.height <= 1.0) { 3 return (UIImageView *)view; 4 } 5 for (UIView *subview in view.subviews) { 6 UIImageView *imageView = [self findHairlineImageViewUnder:subview]; 7 if (imageView) { 8 return imageView; 9 } 10 } 11 return nil; 12 }
4)最后在viewWillAppear,viewWillDisappear中处理
1 - (void)viewWillAppear:(BOOL)animated { 2 [super viewWillAppear:animated]; 3 navBarHairlineImageView.hidden = YES; 4 } 5 6 - (void)viewWillDisappear:(BOOL)animated { 7 [super viewWillDisappear:animated]; 8 navBarHairlineImageView.hidden = NO; 9 }
效果如下:
PS:第二种方法可以保持bar的translucent
本文永久地址:http://blog.it985.com/9808.html
本文出自 IT985博客 ,转载时请注明出处及相应链接。