AppDelegate+Appearance
记录iOS15之后,nav 和 tabbar 等一些的全局设置
#import "AppDelegate+Appearance.h"
@implementation AppDelegate (Appearance)
- (BOOL)Appearance_application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self setupNav];
[self setupTabBar];
[self setupTableView];
return YES;
}
/**
nav
*/
-(void)setupNav{
UINavigationBar *navigationBar = [UINavigationBar appearance];
[navigationBar setTranslucent:NO];
navigationBar.tintColor = [UIColor whiteColor];
[navigationBar setBarStyle:UIBarStyleDefault];
//隐藏Nav下边的线
[navigationBar setShadowImage:[UIImage new]];
[navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
[navigationBar setBackIndicatorImage:IMG_BACK_Blue];
[navigationBar setBackIndicatorTransitionMaskImage:IMG_BACK_Blue];
[[UIBarButtonItem appearance] setTintColor:[UIColor blackColor]];
// 问题:导航栏问题比较明显,有的变白色,有的变黑色。
// 原因:UINavigationBar 部分属性的设置在 iOS15 上是无效的
if (@available(iOS 13.0, *)) {
UINavigationBarAppearance * appearance = [[UINavigationBarAppearance alloc] init];
appearance.backgroundColor = [UIColor whiteColor];// 背景色
appearance.shadowColor = [UIColor clearColor];// 去除导航栏阴影(如果不设置clear,导航栏底下会有一条阴影线)
appearance.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor blackColor],
NSFontAttributeName : [UIFont alyRegularFontWithFontSize:16]};// 字体颜色 字体
[UINavigationBar appearance].scrollEdgeAppearance = appearance;// 带scroll滑动的页面
[UINavigationBar appearance].standardAppearance = appearance;// 常规页面
}
}
/**
TabBar
*/
-(void)setupTabBar{
if (@available(iOS 13.0, *)) {
UITabBarAppearance *appearance = [UITabBarAppearance new];
appearance.backgroundColor = [UIColor whiteColor];
appearance.shadowColor = [UIColor clearColor]; // 去除tab 顶部黑线
appearance.shadowImage = [UIImage new];
[UITabBar appearance].standardAppearance = appearance;
if (@available(iOS 15.0, *)) {//iOS15 适配
[UITabBar appearance].scrollEdgeAppearance = appearance;
}
}
}
/**
TableView
*/
-(void)setupTableView{
if (@available(iOS 15.0, *)) {
[UITableView appearance].sectionHeaderTopPadding = 0;
}
}
@end
UINavigationController+ALYSetNavBar
设置navbar 透明 和 其他颜色。返回按钮图片
self.navigationBar.translucent = YES; // 透明
self.navigationBar.translucent = NO; // 不透明
/**
改变nav 背景色 标题色
*/
-(void)customNavBackColor:(UIColor *)color_bg titleColor:(UIColor *)color_t{
if (@available(iOS 13.0, *)) {
UINavigationBarAppearance * appearance = [[UINavigationBarAppearance alloc] init];
appearance.backgroundColor = color_bg;// 背景色
appearance.shadowColor = [UIColor clearColor];// 去除导航栏阴影(如果不设置clear,导航栏底下会有一条阴影线)
appearance.titleTextAttributes = @{NSForegroundColorAttributeName: color_t,
NSFontAttributeName : [UIFont alyRegularFontWithFontSize:16]};// 字体颜色 字体
[UINavigationBar appearance].scrollEdgeAppearance = appearance;// 带scroll滑动的页面
[UINavigationBar appearance].standardAppearance = appearance;// 常规页面
}else{
self.navigationController.navigationBar.barTintColor = color_bg;// 背景色
self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: color_t,
NSFontAttributeName : [UIFont alyRegularFontWithFontSize:16]};// 字体颜色 字体
}
}
/**
改变nav 背景色 标题色 返回按钮图片
*/
-(void)customNavBackColor:(UIColor *)color_bg titleColor:(UIColor *)color_t backBtnImg:(UIImage *)img{
[self customNavBackColor:color_bg titleColor:color_t];
self.navigationItem.leftBarButtonItem = [self addBackWithImg:img];
}
网友评论