KAR KAR - 2 months ago 18
Objective-C Question

Display image from path in imageView in ios

I have image path and I want to display it in uiimageview,


/Users/WTS-New/Library/Developer/CoreSimulator/Devices/F43C‌​26D2-DCFF-4764-AAF0-‌​F6CC7BCDCF5D/data/Co‌​ntainers/Data/Applic‌​ation/8E49D340-7CAC-‌​4031-85BF-9E5C26A1E3‌​7A/Documents/Small-m‌​ario.png


How can I get image to displayed?

Answer

Try using below code:

Get image path from Image name:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *imageFilePath;
NSError *err;

imageFilePath = [documentsDirectory stringByAppendingPathComponent:@"Small-m‌​ario.png"];

Set image using imageWithContentsOfFile method:

YourImageView.image = [UIImage imageWithContentsOfFile: imageFilePath]; 
Comments