為了組件化,我們的工程會將一些公用的組件進行pod制作,如果你封裝的組件是有關(guān)于UI的,那么pod中可能會用到圖片資源,如果只是簡單的使用[UIImage imageWithName:]方法可能會獲取不到image,這個可能是由于對應(yīng)的資源調(diào)用的類可能沒有找到自己關(guān)聯(lián)的bundle中的資源。解決方法如下:
1、先獲取調(diào)用資源的類的關(guān)聯(lián)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