如何获取所有图像名称? [英] How to fetch all image names?

查看:42
本文介绍了如何获取所有图像名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取一个文件夹中的所有图像名称.

I want to fetch all image names that are in one folder.

我想做的是,将所有图像放在一个名为文件"的文件夹中.

What I want to do is, I put all images in a folder named:"Files"

现在可以将所有图像名称添加到数组中了,所以我不需要手动将所有图像名称写入数组中,或者有其他简单的方法可以做到这一点吗?

推荐答案

NSFileManager *filemgr;
NSArray *dirlist;

path= [NSString stringWithFormat:@"%@/%@",[[NSBundle mainBundle] bundlePath],@"Folder_Name"];

    filemgr =[NSFileManager defaultManager];

dirlist = [filemgr contentsOfDirectoryAtPath:path error:NULL];

NSString *directory =[NSString stringWithFormat:@"%@/%@",path,[dirlist objectAtIndex: index]] ;

NSLog(@"Path:%@",directory);
NSArray *temp = [filemgr contentsOfDirectoryAtPath:directory error:NULL];

注意:当您在项目中添加图片的文件夹时,请记住选择创建文件夹引用"选项.

Note : When you add your image's folder in project , please remember to select " Create folder reference " option.

使用此整个图像路径:

    imagesUrls = [[NSMutableArray alloc]init];
    for(int j =0; j< [temp count]; j++) 
    {
        [imagesUrls addObject:[NSString stringWithFormat:@"%@/%@",directory,[temp objectAtIndex:j]]];

    }

最后使用imagesUrls数组获取图像的路径.

Finally use imagesUrls array to get the path of image.

imageView.image =[UIImage imageWithContentsOfFile:[imagesUrls objectAtIndex:i]];

这篇关于如何获取所有图像名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆