話不多說,直接上代碼
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController.navigationBar.subviews enumerateObjectsUsingBlock:^(UIView *view, NSUInteger idx, BOOL *stop) {
if (@available(iOS 10.0, *)) {
if (@available(iOS 13.0, *)) {
self.navigationController.navigationBar.subviews[0].subviews[0].hidden = YES;
}else {
self.navigationController.navigationBar.subviews[0].subviews[1].hidden = YES;
}
}else{
//iOS10之前使用的是_UINavigationBarBackground
if ([view isKindOfClass:NSClassFromString(@"_UINavigationBarBackground")]) {
[view.subviews firstObject].hidden = YES;
}
}
}];
}