CNLivePerAuthGetImage.m 1.38 KB
//
//  CNLivePerAuthGetImage.m
//  CNLiveBPersonalVerificationModule
//
//  Created by 殷巧娟 on 2020/4/6.
//

#import "CNLivePerAuthGetImage.h"

@implementation CNLivePerAuthGetImage
/**
 *  创建图片
 *
 *  @param imageName 图片名字
 *  @param bundlePath 图片所在的bundle名字
 *  @param targetClass 类和bundle的同级目录
 *  @return 返回UIImage
 */
+ (UIImage *)cnLivePerAuth_getImageName:(NSString *)imageName bundle:(NSString *)bundlePath targetClass:(Class)targetClass{
    
    NSInteger scale = [[UIScreen mainScreen]scale];
    NSBundle *bundle = [NSBundle bundleForClass:targetClass];
    NSURL *url = [bundle URLForResource:bundlePath withExtension:@"bundle"];
    
    if (!url) {
        return [UIImage new];
    }
    NSBundle *targetBundle = [NSBundle bundleWithURL:url];
    if (!targetBundle) {
        return [UIImage new];
    }
    NSString *imgName = [NSString stringWithFormat:@"%@@%zdx.png",imageName,scale];
    UIImage *image = [UIImage imageNamed:imgName inBundle:targetBundle compatibleWithTraitCollection:nil];
    if (image) {
        return image;
    }else {
        if ([UIImage imageNamed:imgName inBundle:[NSBundle mainBundle] compatibleWithTraitCollection:nil]) {
            return [UIImage imageNamed:imgName inBundle:[NSBundle mainBundle] compatibleWithTraitCollection:nil];
        }else{
            return [UIImage new];
        }
    }

}
@end