发布时间:2023-08-13 18:00
// iOS 15.0 之前设置 navigationBar 的代码
UINavigationBar *bar = [UINavigationBar appearanceWhenContainedInInstancesOfClasses:@[[CustomNavigationController class]]];
bar.barTintColor = [UIColor redColor];
bar.barStyle = UIBarStyleDefault;
[bar setTranslucent:NO]; //设置不透明
bar.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor greenColor], NSFontAttributeName: [UIFont systemFontOfSize:25]};
// iOS 15 之后,这样设置导航条的相关属性才正确。之前的做法已失效
UINavigationBarAppearance *navBarAppearance = [[UINavigationBarAppearance alloc]init];
[navBarAppearance configureWithOpaqueBackground];
navBarAppearance.backgroundColor = [UIColor redColor];
[navBarAppearance setTitleTextAttributes:
@{NSForegroundColorAttributeName:[UIColor blackColor]}];
UINavigationBar *navBar = [UINavigationBar appearanceWhenContainedInInstancesOfClasses:@[[CustomNavigationController class]]];
navBar.standardAppearance = navBarAppearance;
navBar.scrollEdgeAppearance = navBarAppearance;