- 图片获取
pod库里面的图片,不能直接通过+ (nullable UIImage *)imageNamed:(NSString *)name
获取,imageNamed:
获取的图片是mainbundle
里面,
pod里面的资源有自己的bundle


打开项目的包内容,可以看到Assets里面的图片保存在与框架同名的bundle里面,因此取图片时需要从此bundle里面取


//获取当前类文件所在的bundle
NSBundle *currentBundle = [NSBundle bundleForClass:[self class]];
//获取bundle名称
NSString *currentBundleName = [NSString stringWithFormat:@"%@.bundle",currentBundle.infoDictionary[@"CFBundleName"]];
//获取图片的路径,注意需要传bundle名称
NSString *backImgPath = [currentBundle pathForResource:@"backImage@3x.png" ofType:nil inDirectory:currentBundleName];
//获取图片
backButtonImage = [[UIImage imageWithContentsOfFile:backImgPath] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
网友评论