如何修复 Cocoapods 中丢失的图像资源?
How to fix missing image resources in Cocoapods?
我加了use_frameworks!到我的 Podfile,现在 Pods 中缺少一些图像资源——当我 运行 项目时,那些 Pods 中包含的图像不再出现。我该如何解决这个问题?
当您将 Pods 构建为框架时,图像文件将放在框架中,而不是主包中。 Pods 中的代码在创建 UIImage
对象时需要为框架指定包。
NSBundle* bundle = [NSBundle bundleForClass:[self class]];
UIImage* image = [UIImage imageNamed:@"image.png"
inBundle:bundle
compatibleWithTraitCollection:nil];
我加了use_frameworks!到我的 Podfile,现在 Pods 中缺少一些图像资源——当我 运行 项目时,那些 Pods 中包含的图像不再出现。我该如何解决这个问题?
当您将 Pods 构建为框架时,图像文件将放在框架中,而不是主包中。 Pods 中的代码在创建 UIImage
对象时需要为框架指定包。
NSBundle* bundle = [NSBundle bundleForClass:[self class]];
UIImage* image = [UIImage imageNamed:@"image.png"
inBundle:bundle
compatibleWithTraitCollection:nil];