CNLivePerAuthGetImage.m
1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//
// 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