iOS 15适配

在baseVC 的viewWillAppear 方法中添加如下代码:

if (@available(iOS 15.0, *)){
        //tableview 下移22
        UITableView *tableview =  (UITableView *)  [self getSubViewWithClassName:@"UITableView" inView:self.view] ;
        if (tableview) {
            tableview.sectionHeaderTopPadding = 0;
        }
        
        //navi
        UINavigationBarAppearance * appearance = [[UINavigationBarAppearance  alloc] init];
        appearance.backgroundColor = [UIColor whiteColor];
        appearance.shadowColor = [UIColor whiteColor];
        UIImage *lineImage = [CTMyTool imageWithColor:Color_Separateline andHeight:1];
        appearance.shadowImage = lineImage;
        appearance.titleTextAttributes = @{NSFontAttributeName:REGULAR_FONT(18),NSForegroundColorAttributeName:Color_Title};

        appearance.backgroundEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
        self.navigationController.navigationBar.standardAppearance = appearance;
        self.navigationController.navigationBar.scrollEdgeAppearance = appearance;
    }
    //tab透明色
    if (@available(iOS 13.0, *)) {
         UITabBarAppearance * appearance = [[UITabBarAppearance alloc] init];
        appearance.backgroundEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
          // 背景色
         appearance.backgroundColor = [UIColor whiteColor];
        appearance.shadowColor = [UIColor whiteColor];
        appearance.stackedLayoutAppearance.normal.titleTextAttributes = @{NSFontAttributeName:REGULAR_FONT(12),NSForegroundColorAttributeName:Color_Tabbar_Normal};
        appearance.stackedLayoutAppearance.selected.titleTextAttributes = @{NSFontAttributeName:REGULAR_FONT(12),NSForegroundColorAttributeName:Color_Tabbar_Normal};
        self.tabBarController.tabBar.standardAppearance = appearance;
         if (@available(iOS 15.0, *)) {
             self.tabBarController.tabBar.scrollEdgeAppearance = appearance;
         }
     }

查找tableview 的方法如下:

-(UIView *)getSubViewWithClassName:(NSString *)className inView:(UIView *)inView {
   //判空处理
   if(!inView || !inView.subviews.count || !className || !className.length || [className isKindOfClass:NSNull.class]) return nil;
   //最终找到的view,找不到的话,就直接返回一个nil
   UIView *foundView = nil;
   //循环递归进行查找
   for(UIView *view in inView.subviews) {
       //如果view是当前要查找的view,就直接赋值并终止循环递归,最终返回
       if([view isKindOfClass:NSClassFromString(className)]) {
           foundView = view;
           break;
       }
       //如果当前view不是要查找的view的话,就在递归查找当前view的subviews
       foundView = [self getSubViewWithClassName:className inView:view];
       //如果找到了,则终止循环递归,最终返回
       if (foundView) break;
   }
   return foundView;
}

颜色转图片方法:

/**
 *  颜色转图片
 *
 *  @param color   高度
 *  @return UIView
 */
+ (UIImage *)imageWithColor:(UIColor *)color andHeight:(CGFloat)height
{
    CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, height);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return image;
}

猜你喜欢

转载自blog.csdn.net/weixin_42050662/article/details/120523548