I am trying to set image to UIImageView programmatically but it does’t work. I have following code.
[image setImage:[UIImage imageNamed:[self localImagePath:NO]]];
and
-(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"];
}
}
Is it possible to set image to UIImageView on run time from different mediums?
The
imageNamed:method takes only the filename as an argument, not a path. Also it will look for that file in the main bundle only. Try usingimageWithContentsOfFile:instead.