当 ImageView 的源是从属性检查器中预先设置时,文件的实际路径何时/如何解析?似乎没有对 NSBundle 的任何调用,但我可能错了。
编辑:我正在尝试调配调用的任何方法(如果可能)以便稍后动态替换 Assets 。
最佳答案
UIImage
初始化器或工厂都没有被调用。
我用调试器(在 iOS 模拟器 7.0.3 上)做了一些研究,发现如下:
1) IB中设置的UIImageView
通过-initWithCoder:
初始化。
2) 在 initWithCoder:
中调用方法 decodeObjectForKey:
。并且 (!) 名为 UIImage
的键包含来自 IB 的图像。此图像通过 ivar 设置为 UIImageView
,而不是通过 setImage:
setter。
因此,似乎 IB 在编译时将原始图像数据打包到 XIB/Storyboard 中。废话,但事实。
这就是为什么我们不能调配 +imageNamed:
或其他工厂,而应该使用条件代码为 retina4 和 iOS6 设置图像
编辑:
评论显示编译后的IB文件的hexdumping中有png名称。
In fact, looking at the output of "hexdump -C BYZ-38-t0r-view-8bC-Xf-vdC.nib " indicates that the filename of the PNG appears in the compiled file. So, it must be loading the file data via the file name from the same bundle.
但是,它们仍然通过某种内部机制加载,而不是通过 imageNamed:
关于ios - 当从 Interface Builder 设置 UIImageView 的图像时,该图像是如何加载的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16908584/