美文网首页
pod使用[UIImage imageWithName:]无法加

pod使用[UIImage imageWithName:]无法加

作者: nuannuan_nuan | 来源:发表于2016-05-31 14:16 被阅读1682次

为了组件化,我们的工程会将一些公用的组件进行pod制作,如果你封装的组件是有关于UI的,那么pod中可能会用到图片资源,如果只是简单的使用[UIImage imageWithName:]方法可能会获取不到image,这个可能是由于对应的资源调用的类可能没有找到自己关联的bundle中的资源。解决方法如下:

1、先获取调用资源的类的关联bundle,NSBundle*myBundle = [NSBundlebundleForClass:[ClassA class]];

2、获取该bundle所在的path,然后拼接图片资源名称:

NSString *path = [[ myBundle resourcePath]stringByAppendingPathComponent:name]];

3、使用image = [UIImageimageWithContentsOfFile:path];获取图片

参考链接:
ios - Pod (PaymentKit) can't load images using imageNamed - Stack Overflow

ios - Impossible to load an image in xcassets on bundle - Stack Overflow

相关文章

网友评论

      本文标题:pod使用[UIImage imageWithName:]无法加

      本文链接:https://www.haomeiwen.com/subject/woicdttx.html