[英]how to load image to uiimageview
how to load image to uiimageview from a custom folder 如何从自定义文件夹将图像加载到uiimageview
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder
NSString*ext= [NSString stringWithFormat:@"/Imagenes/30775.png"];
NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:ext];
//option 1
UIImage * myImage = [UIImage imageWithContentsOfFile: dataPath];
_img.image = myImage
///option 2
UIImageView * myImageView = [[UIImageView alloc] initWithImage: myImage];
_img = myImageView;
///option 3
NSData *imgData = [[NSData alloc] initWithContentsOfURL:[NSURL fileURLWithPath:dataPath]];
_img.image = [UIImage imageWithData:imgData];
i try 3 options but not working any idea ? 我尝试3个选项,但是不起作用?
the image is loading from a custom folder i checked the path and is correct but not load 图片是从自定义文件夹加载的,我检查了路径,但正确但未加载
Your path @"/Imagenes/30775.png" seems to be wrong. 您的路径@“ / Imagenes / 30775.png”似乎是错误的。 Double check it.
仔细检查。 Otherwise following should work
否则以下应该工作
UIImage * myImage = [UIImage imageWithContentsOfFile: dataPath];
_img.image = myImage
NSString*ext= [NSString stringWithFormat:@"/Imagenes/30775.png"];
Your path is wrong.I guess the Imagenes is a group in your project. 您的路径错误。我想Imagenes是您项目中的一个小组。 So xcode is not create a folder in your project main folder.
因此,xcode不会在项目主文件夹中创建一个文件夹。 The groups is only helps you to view the files easily in the xcode program.
组仅帮助您在xcode程序中轻松查看文件。 Also you don't need
stringWithFormat
. 另外,您不需要
stringWithFormat
。
Try this; 尝试这个;
NSString*ext= @"30775.png";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.