我想以編程方式將圖像設置爲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