xocde13上打包app的适配方案记录
1.navigationbar变透明
解决方法:
@implementation** UINavigationController (Extension) /// 更改为颜色 - (void)changeBackgroundColor:(UIColor *)color { static UIImage *backgroundImage = nil; static UIImage *shadowImage = nil; if (!backgroundImage) { backgroundImage = [LGImage imageWithColor:color]; shadowImage = [LGImage imageWithColor:[UIColor clearColor]]; } if (@available(iOS 13.0, *)) { // iOS13 之后用这个 UINavigationBarAppearance *apparance = [[UINavigationBarAppearance alloc] init]; [apparance configureWithOpaqueBackground]; apparance.backgroundColor = color; [apparance setShadowImage:shadowImage]; self.navigationBar.standardAppearance = apparance; self.navigationBar.scrollEdgeAppearance = self.navigationBar.standardAppearance; } else { // iOS15之后失效 [self.navigationBar setBackgroundImage:backgroundImage forBarMetrics:UIBarMetricsDefault]; [self.navigationBar setShadowImage:shadowImage]; } } /// 更改为图片 - (void)changeBackgroundImage:(UIImage *)image { static UIImage *shadowImage = nil; if (!shadowImage) { shadowImage = [LGImage imageWithColor:[UIColor clearColor]]; } if (@available(iOS 13.0, *)) { UINavigationBarAppearance *apparance = [[UINavigationBarAppearance alloc] init]; [apparance configureWithOpaqueBackground]; apparance.backgroundColor = [UIColor clearColor]; [apparance setShadowImage:shadowImage]; self.navigationBar.standardAppearance = apparance; [self.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault]; self.navigationBar.scrollEdgeAppearance = self.navigationBar.standardAppearance; } else { [self.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault]; [self.navigationBar setShadowImage:shadowImage]; } } @end 复制代码
2.tabbar变透明
- (void)changeBackgroundColor:(UIColor *)color{ if (@available(iOS 15.0, *)) { //iOS15后添加更改tabbar新类,用这个更改背景色 UITabBarAppearance *appearance = [[UITabBarAppearance alloc] init]; [appearance configureWithOpaqueBackground]; appearance.backgroundColor = color; self.tabBar.standardAppearance = appearance; self.tabBar.scrollEdgeAppearance = appearance; } } 复制代码
3.iphone13 mini顶部安全区域更改需要注意
作者:Rui4u君
链接:https://juejin.cn/post/7019216813397377032