iOS13以上通过传统的barTintColor会异常,需要区分版本设置
if (@available(iOS 13.0, *)) {
UINavigationBarAppearance *appearance = [[UINavigationBarAppearance alloc] init];
appearance.backgroundImage= [UIImage imageNamed:@"hengtu1"];//图片
appearance.backgroundColor= [UIColor blueColor];//背景色
appearance.shadowColor = UIColor.clearColor; //阴影
appearance.titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor whiteColor]};//导航栏标题颜色
self.navigationController.navigationBar.standardAppearance = appearance;
self.navigationController.navigationBar.scrollEdgeAppearance = appearance;
} else {
self.navigationController.navigationBar.barTintColor = [UIColor blueColor];
}