一、适配导航条的两种方式
if (@available(iOS 15.0, *)) {
UINavigationBarAppearance *appearance = [UINavigationBarAppearance new];
[appearance configureWithOpaqueBackground];
appearance.backgroundColor = [UIColor cyanColor];
// UIBarButtonItemStateAppearance *normal = appearance.buttonAppearance.normal;
// UIBarButtonItemStateAppearance *highlighted = appearance.buttonAppearance.highlighted;
// highlighted.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor],
// NSFontAttributeName:[UIFont systemFontOfSize:20]};
// normal.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor],
// NSFontAttributeName:[UIFont systemFontOfSize:20]};
appearance.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor],
NSFontAttributeName:[UIFont systemFontOfSize:20]};
self.navigationBar.standardAppearance = appearance;
self.navigationBar.scrollEdgeAppearance=self.navigationBar.standardAppearance;
}else{
self.navigationBar.barTintColor = [UIColor redColor];
self.navigationBar.translucent = YES;
self.navigationBar.tintColor = [UIColor whiteColor];
[self.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor],
NSFontAttributeName:[UIFont systemFontOfSize:20]}];
}
[self.view insertSubview:self.barView belowSubview:self.navigationBar];
[self.barView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.offset(0);
make.left.offset(0);
make.right.offset(0);
CGFloat height = [AppManager vcTopHight];
make.height.mas_equalTo(height);
;
}];
[self.navigationBar setBackgroundImage: [UIImage new] forBarMetrics:UIBarMetricsDefault];
[self.navigationBar setShadowImage:[UIImage new]];
[self.navigationBar setTintColor:[UIColor clearColor]];
二、一些工程不得不变成 New Build System引发编译不过的解决方法:
Build Phases里某些地方的 Run script勾选上 For install builds only即可。
三、tabBar
UITabBarAppearance *appearance = [[UITabBarAppearance alloc] init];
//tabBaritem title选中状态颜色
appearance.stackedLayoutAppearance.selected.titleTextAttributes = @{
NSForegroundColorAttributeName:[UIColor blueColor],
};
//tabBaritem title未选中状态颜色
appearance.stackedLayoutAppearance.normal.titleTextAttributes = @{
NSForegroundColorAttributeName:[UIColor blueColor],
};
//tabBar背景颜色
appearance.backgroundColor = [UIColor blackColor];
self.tabBarItem.scrollEdgeAppearance = appearance;
self.tabBarItem.standardAppearance = appearance;
其中 standardAppearance和scrollEdgeAppearance等的区别
standardAppearance --- 常规状态
scrollEdgeAppearance --- 小屏幕手机横屏时的状态
scrollEdgeAppearance --- 呗scrollview向下拉的状态
四,未完待续
网友评论