一般情况下image的加载会使用UIImage imageNamed:
方法进行加载。这在runtime的情况下是正常进行的。
但在xib中则无法显示,解决方案:
使用进行加载:
+ (nullable UIImage *)imageNamed:(NSString *)name inBundle:(nullable NSBundle *)bundle compatibleWithTraitCollection:(nullable UITraitCollection *)traitCollection NS_AVAILABLE_IOS(8_0)
其中参数bundle使用[NSBundle bundleForClass:]
使用[self class]/[当前类 class],切记不可用[NSBundle mainBundle]
关于其中原因:
一段据称来自官方的回应
Engineering has determined that this issue behaves as intended based on the following:
We can’t really make this any easier than specifying the bundle. You might say, “oh, let’s swizzle -[NSBundle mainBundle]”, but lots of call sites that reference a bundle don’t go thr