如何在three20的照片浏览器中加载本地图片

时间:2011-08-18 13:15:05

标签: ios cocoa-touch ipad three20

在three20的TTCatalog演示中,PhotoTest1Controller.m。有一些代码

[[[MockPhoto alloc]
initWithURL:@"http://ww4.sinaimg.cn/bmiddle/6e8f23a5jw1dk7pylzs8ij.jpg"
smallURL:@"http://ww4.sinaimg.cn/thumbnail/6e8f23a5jw1dk7pylzs8ij.jpg"
size:CGSizeMake(320, 480)] autorelease],

我可以用本地路径替换这些URL。 我将图片放入应用程序包中。

1 个答案:

答案 0 :(得分:0)

文件网址(file://)应该可以正常使用。对于应用包中的图片,您可以使用-[NSBundle URLForResource:withExtension:]

NSURL *imageURL = [[NSBundle mainBundle] URLForResource:@"foo" withExtension:@"jpg"];

在iOS< 4.0您必须将基于路径的NSBundle方法与+[NSURL fileURLWithPath:]

结合使用
NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"foo" ofType:@"jpg"];
NSURL *imageURL = [NSURL fileURLWithPath:imagePath];