我想以编程方式将图像设置为UIImageView,但它不起作用。我有以下代码。IPhone UIImageView图像
[image setImage:[UIImage imageNamed:[self localImagePath:NO]]];
和
-(NSString *)localImagePath:(BOOL)forSave {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSPicturesDirectory, NSUserDomainMask, YES);
NSString *picturesDirectory = [paths objectAtIndex:0];
NSString *picturesPath = [picturesDirectory stringByAppendingPathComponent:@"image.png"];
if (forSave || [[NSFileManager defaultManager] fileExistsAtPath:picturesPath]) {
return picturesPath;
}
else {
return [[NSBundle mainBundle] pathForResource:@"image" ofType:@"png"];
}
}
是否有可能像设置为UIImageView的来自不同媒介的运行时间?
我试过你,它在半测试中工作。我仍然需要做全面的测试。你确定函数“imageWithContentsOfFile”将适用于图片目录中的图片吗? – Neutralizer 2011-03-02 15:55:22