在Interface Builder中设置UIImageView的图像 [英] Setting the image of a UIImageView in Interface Builder

查看:93
本文介绍了在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.

这篇关于在Interface Builder中设置UIImageView的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆