升级iOS10之后意外发现之前设置隐藏好的标题栏底部的横线又冒出来了,原来是横线的UIImageView的位置改变了,出现在一个UIBarBackground的View里面。为了兼容iOS10之前的显示效果,贴出下面的解决办法。欢迎批评指正。
#define IOSVersion[[[UIDevice currentDevice] systemVersion] floatValue]
//去掉NavigationBar底部的那条黑线
if([self.navigationBarrespondsToSelector:@selector(setBackgroundImage:forBarMetrics:)]){
NSArray*list =self.navigationBar.subviews;
NSIntegerindex =0;
for(UIView* objinlist) {
//iOS10
if(IOSVersion>=10&& index ==0){
NSArray*list2 = obj.subviews;
for(UIView* obj2inlist2) {
NSLog(@"%@",obj2);
if([obj2isKindOfClass:[UIImageViewclass]]){
obj2.hidden=YES;
}
}
}
//iOS9或以下
if([objisKindOfClass:[UIImageViewclass]]) {
UIImageView*imageView = (UIImageView*)obj;
NSArray*list2 = imageView.subviews;
for(idobj2inlist2) {
if([obj2isKindOfClass:[UIImageViewclass]]) {
UIImageView*imageView2 = (UIImageView*)obj2;
imageView2.hidden=YES;
}
}
}
index++;
}
}
PS:简书的代码编辑蛋疼的可以啊~