Ipad项目的相对路径

时间:2012-10-13 10:17:17

标签: ipad relative-path

我知道这是一个愚蠢的问题,但我无法找出我的相对路径是什么...... :(

我有一个iPad项目,下面有一个图像文件夹

enter image description here

我想设置一个UIImage,但我无法弄清楚我的相对路径是什么 -

我试过了:

UIImage *image = [[UIImage alloc]initWithContentsOfFile:@"/Images/send.png"];

但它没有用......

祝你好运

1 个答案:

答案 0 :(得分:0)

如果您的图片中包含图片,则无需查找相对路径。但是[[NSBundle mainBundle] bundlePath]会给出您的捆绑包的相对路径。

UIImage *image = [UIImage imageNamed:@"send.png"];

这是加载图像的基本方法。

UIImage *image = [[UIImage alloc]initWithContentsOfFile:@"send.png"];

这样可以更快地加载图像。因为它加载没有缓存的图像。

UIImage *image = [UIImage imageNamed:@"send"];

如果要将图像用于普通和视网膜屏幕,请使用此选项。在你的包中你应该有两个图像“send.png”和“send@2x.png”,其中“send@2x.png”是“send.png”的两倍。