Setting the image of a UIImageView in Interface Builder

痞子三分冷 提交于 2019-12-07 06:02:50

问题


When ever I set an image for a UIImageView in IB and simulate the interface the buttons and stuff show up but the image view doesn't.


回答1:


That's because the simulator used by Interface Builder is independent of your project. It's just taking your xib files, building the interface, and displaying it. As such, any resources it finds references to but can't find will be skipped. So if your UIImageView uses an image named "myImage.png", then when the simulator runs, it's going to try to execute [UIImage imageNamed:@"myImage.png"];. Since "myImage.png" is not part of the Simulator bundle, it will fail to create the image, and your UIImageView will be blank.

It can create buttons because (obviously) buttons are standard, globally available code. Your project-specific resources are not.



来源:https://stackoverflow.com/questions/1734586/setting-the-image-of-a-uiimageview-in-interface-builder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!