ios - 当从 Interface Builder 设置 UIImageView 的图像时,该图像是如何加载的?

标签 ios cocoa-touch uiimageview interface-builder nsbundle

当 ImageView 的源是从属性检查器中预先设置时,文件的实际路径何时/如何解析?似乎没有对 NSBundle 的任何调用,但我可能错了。

编辑:我正在尝试调配调用的任何方法(如果可能)以便稍后动态替换 Assets 。

enter image description here

最佳答案

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/

相关文章:

ios - 无法修改 PFLogInViewController logInButton 标题

iphone - 寻找 CGPath 的中心

iphone - 如何在 iPhone 的表格 View 单元格中设置背景图像

当前设备的启动图像的 IOS UIImage

ios - 更新标签使 UIImageview 不可见的线程问题

swift - 如何在 Xcode swift 3 中的两个 ImageView 中显示相同的选取图像?

objective-c - iBooks 喜欢动画

ios - Swift - 按下 BarButtonItem 时以编程方式创建和显示 UIPickerView

objective-c - 音乐音阶:循环播放不同音符的功能

iphone - NSPredicate 使用特殊字符过滤