第一種方法师倔。(可以保證導(dǎo)航條原來的透明)
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.navigationController.navigationBar.barTintColor = [UIColor whiteColor];
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;
NSArray *list2=imageView.subviews;
for (id obj2 in list2) {
if ([obj2 isKindOfClass:[UIImageView class]]) {
UIImageView *imageView2=(UIImageView *)obj2;
imageView2.hidden=YES;
}
}
}
}
}
}
第二種方式哩簿。(這種方式相對簡單一些,但是這種效果會去掉導(dǎo)航條的透明效果)
[[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];
第三種方式躏升。(比較常用辩棒,也比較實用)
//隱藏分割線
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
self.navigationController.navigationBar.barTintColor = [UIColor whiteColor];
self.navigationImageView = [self findHairlineImageViewUnder:self.navigationController.navigationBar];
self.navigationImageView.hidden = YES;
}
//顯示分割線
-(void)viewDidDisappear:(BOOL)animated{
[super viewDidDisappear:animated];
self.navigationImageView.hidden = NO;
}
//實現(xiàn)的方法
-(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 = [self findHairlineImageViewUnder:subview];
if (imageView) {
return imageView;
}
}
return nil;
}
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者