iOS 隐藏导航栏的分割线


@interface ViewController{

UIImageView*navBarHairlineImageView;

}


2)在viewDidLoad中加入:


navBarHairlineImageView = [selffindHairlineImageViewUnder:self.navigationController.navigationBar];


3)实现找出底部横线的函数


- (UIImageView*)findHairlineImageViewUnder:(UIView*)view {

if([view isKindOfClass:UIImageView.class] && view.bounds.size.height<=1.0) {

return(UIImageView*)view;   

 }

for(UIView*subview in view.subviews) {

UIImageView*imageView = [selffindHairlineImageViewUnder:subview];

if(imageView) {

return imageView;        

}    

}return nil;

}



4)最后在viewWillAppear,viewWillDisappear中处理

- (void)viewWillAppear:(BOOL)animated {    

[superviewWillAppear:animated];    

navBarHairlineImageView.hidden=YES;

}

- (void)viewWillDisappear:(BOOL)animated {    

[superviewWillDisappear:animated];  

  navBarHairlineImageView.hidden=NO;

}


===========================================================================

下面来一个最简单的:

UINavigationBar*navigationBar =self.navigationController.navigationBar;

// bg.png为自己ps出来的想要的背景颜色。

[navigationBar setBackgroundImage:[UIImageimageNamed:@"bg.png"] forBarPosition:UIBarPositionAny                      barMetrics:UIBarMetricsDefault];

[navigationBar setShadowImage:[UIImagenew]];

这是唯一一个隐藏这条线的官方用法,但是有一个缺陷-删除了translucency(半透明)

你可能感兴趣的:(iOS 隐藏导航栏的分割线)