iOS開發(fā)大部分情況下會(huì)使用到導(dǎo)航欄谜悟,由于我司的app導(dǎo)航欄需要與下面緊挨著的窗口顏色一致伙狐,導(dǎo)航欄底部的橫線就會(huì)影響這個(gè)美觀氓奈。
去除方法之一:(推薦)
UIImageView *backgroundView = [self.navigationController.navigationBar valueForKey:@"_backgroundView"];
for(UIView *view in backgroundView.subviews) {
if(view.bounds.size.height <= 1.0f) {
[view removeFromSuperview];
}
}
去除方法之二(不推薦,太復(fù)雜)蜓肆。
1)聲明UIImageView變量,存儲(chǔ)底部橫線
@interface MyViewController {
UIImageView *navBarHairlineImageView;
}
2)在viewDidLoad中加入:
navBarHairlineImageView = [self findHairlineImageViewUnder:self.navigationController.navigationBar];
3)實(shí)現(xiàn)找出底部橫線的函數(shù)
- (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;
}
4)最后在viewWillAppear颜凯,viewWillDisappear中處理
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
navBarHairlineImageView.hidden = YES;
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
navBarHairlineImageView.hidden = NO;
}
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者