读取Photos全部图标的方法(转)

来源:互联网 发布:空气质量 数据 编辑:程序博客网 时间:2024/06/05 18:37

NSString *mainDir=[NSString stringWithFormat:@"/var/mobile/Media/Photos/Thumbs"]; //所有照片都存在该路径下
NSArray *childrenFilenames = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:mainDir error:nil];
float i=0.0,j=0.0;
for(NSString *fn in childrenFilenames) {
NSString *tempStr=[mainDir stringByAppendingPathComponent:fn];
NSDictionary *attributes = [[NSFileManager defaultManager] fileAttributesAtPath:tempStr traverseLink:NO];
BOOL isDirectory=[[attributes objectForKey:NSFileType] isEqualToString:NSFileTypeDirectory];
if (isDirectory) {
NSArray *imageFile = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:tempStr error:nil];
NSString *imagePath=[tempStr stringByAppendingPathComponent:[imageFile objectAtIndex:0]];
NSLog(@"the image filedirectory is %@",imagePath);
UIImage *img=[UIImage imageWithContentsOfFile:imagePath];
UIImageView *imgView=[[UIImageView alloc] initWithImage:img];
[imgView setFrame:CGRectMake(i, j, 150, 150)];
[self.view addSubview:imgView];
[imgView release];
i+=100.0;
j+=100.0;
}
}

原创粉丝点击