在Interface Builder中设置UIImageView的图像
当我在IB中为UIImageView设置图像并模拟界面时,按钮和内容会显示但图像视图不显示。
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.
这是因为Interface Builder使用的模拟器独立于您的项目。它只是获取你的xib文件,构建界面并显示它。因此,将跳过它找到但无法找到的任何资源。因此,如果您的 UIImageView
使用名为myImage.png的图像,那么当模拟器运行时,它将尝试执行 [UIImage imageNamed:@ myImage.png];
。由于myImage.png不是模拟器包的一部分,因此无法创建图像,并且您的UIImageView将为空白。
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.