推荐两篇文章 https://my.oschina.net/sayonala/blog/511490
http://www.jianshu.com/p/c26f1e36263f
第一篇使用runtime解决 本文附上oc和swift 解决方法
需要将上图中的那条线隐藏掉 遍历self.navigationController.navigationBar.subviews
并不能隐藏掉它 然后看层 百科 它是属于上层的 _UIBarBackground 的(注意前面的下划线不要丢) 所以就变成隐藏_UIBarBackground
这个东西了 上代码:
oc方法
for (UIView * v in self.navigationController.navigationBar.subviews){
UIView * bgview=nil;
NSString * classname = NSStringFromClass([v class]);
if ([classname isEqualToString:@"_UINavigationBarBackground"] || [classname isEqualToString:@"UINavigationBarBackground"])
{
bgview=v;
break;
} else if ([classname isEqualToString:@"_UIBarBackground"]) {
bgview = v;
for (UIView *vi in v.subviews) {
// 适配iOS10
NSString *viName = NSStringFromClass([vi class]);
if ([viName isEqualToString:@"UIImageView"]) {
vi.hidden = YES;
break;
}
}
}
}
swift 方法
privatefuncremoveNavLine() {
for v in (self.navigationController?.navigationBar.subviews)!{
varbgview :UIView? =nil
letclassName =NSStringFromClass(v.classForCoder)
if className.elementsEqual("_UINavigationBarBackground") || className.elementsEqual("UINavigationBarBackground"){
bgview = v
break
}elseifclassName.elementsEqual("_UIBarBackground"){
bgview = v
forviinv.subviews{
letviname =NSStringFromClass(vi.classForCoder)
ifviname.elementsEqual("UIImageView"){
vi.isHidden=true
break
}
}
}
}
}