Search code examples
iosuiscrollviewnsdocumentdirectory

ScrollView:how to load images from Documents


I saved some images in iphoneSimlator/7.0/..../Documents/Archive/.
Now i am working on scroll view.
How to load images from Documents/Archive/ ? I need to display these images on scrollview.


Solution

  • NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    
      NSString *documentsDirectory = [paths objectAtIndex:0];
      NSArray *filePathsArray = [[NSFileManager defaultManager]                                                       
      subpathsOfDirectoryAtPath:documentsDirectory  error:nil];
    
    
    
    
    
    
    for (int i=3; i<[filePathsArray count]; i++)
    {    
        NSString *strFilePath = [filePathsArray objectAtIndex:i];
    
        NSString *fullpath = [NSString stringWithFormat:@"%@/%@",documentsDirectory,strFilePath];
    
        NSLog(@"array with paths of image files in the Document Directory %@", fullpath);
    
    
        UIImage *myImage = [UIImage imageWithContentsOfFile:fullpath];
    
        NSLog(@"array with paths of image files in the Document Directory %@", myImage);
    
        UIImageView *img = [[UIImageView alloc] init];
        img.image = myImage;
    
    
        CGFloat xOrigin = (i - 3) * 320.0f;
    
        img.frame = CGRectMake(xOrigin,-64,320,117);
        [_scrollViewProperty  addSubview:img];
    
    }