在某个文件夹中显示图片,iPhone

时间:2012-02-08 16:29:02

标签: iphone objective-c ios gallery image

有没有办法使用iPhone默认库显示某个文件夹中的图片? 我会试着解释一下我的问题:

我有什么: 我有一个带文字说明的视图,我想通过点击按钮来显示图像。

(我会尝试绘制我的观点)

    ____________________________
   /                            \
   |        °==========         |
   |                            |
   |____________________________|
   ||       NAVIGATION BAR     ||
   ||__________________________||
   ||                          ||
   ||  ______________________  ||
   ||  |                    |  ||
   ||  |                    |  ||
   ||  |                    |  ||
   ||  |   TEXT BOX SPACE   |  ||
   ||  |                    |  ||
   ||  |                    |  ||
   ||  |                    |  ||
   ||  |                    |  ||
   ||  ----------------------  ||
   ||                          ||
   ||     ________________     ||
   ||     | Image button |     ||
   ||     ----------------     ||
   ||__________________________||
   |              _             |
   |             / \            |
   |             \_/            |
   \____________________________/

更新: 图片: http://img851.imageshack.us/img851/8229/schermata022455966alle1.png

我想去哪里:

我在app目录中有一个文件夹(example / Images /) 图片数量不确定。

我想: 1)显示文件夹中的所有图片,使用幻灯片从一个传递到另一个(类似于iPhone图库)

2)显示文件夹中的图片或文件列表,然后选择我想要查看的图片。

查看图像后,请返回说明页。

有可能吗?

更新

替代方式:

假设我可以获得一系列图像。 您是否认为可以将Uiimageview加载到图像中,并使用按钮“刷新”它? 像这样的东西

http://img824.imageshack.us/img824/1016/schermata022455967alle1.png

1 个答案:

答案 0 :(得分:0)

您可以使用:

而不是NSFileManager
NSArray *files = [[NSBundle mainBundle] pathsForResourcesOfType:@"jpeg" inDirectory:@"theFolder"];

显然,构建可扩展的图库以实际显示图像是一项更多的工作。我建议尝试我的iCarousel库,它不会为你完成所有工作,但基本上提供类似于水平表视图的东西,以使其更简单。如果您设置项目间距以匹配屏幕宽度,并使每个轮播屏幕大小,它应该做你想要的。

如果您愿意,您还可以选择使用CoverFlow显示图像,而不仅仅是平面旋转木马; - )

<强>更新

您当然可以使用按钮设置UIImageView图像属性。为每个按钮创建一个IBOutlet用于图像视图和IBActions,然后将这些代码放在动作中(我假设您已经加载了图像文件名并将它们存储在名为imagePaths的数组属性中,并且您还有另一个字符串属性名为currentImagePath):

@property (nonatomic, strong) NSArray *imagePaths;
@property (nonatomic, strong) NSString *currentImagePath;
@property (nonatomic, strong) IBOutlet UIImageView *imageView;

- (IBAction)previousImageButtonAction
{
    NSInteger index = [imagePaths indexOfObject:currentImagePath];
    if (index == NSNotFound) index = 0;
    index = ((index - 1) + [imagePaths count]) % [imagePaths count];
    UIImage *image = [UIImage imageWithContentsOfFile:[imagePaths objectAtIndex:index]];
    imageView.image = image;
}

- (IBAction)nextImageButtonAction
{
    NSInteger index = [imagePaths indexOfObject:currentImagePath];
    if (index == NSNotFound) index = 0;
    index = (index + 1) % [imagePaths count];
    UIImage *image = [UIImage imageWithContentsOfFile:[imagePaths objectAtIndex:index]];
    imageView.image = image;
}

如果正确连接所有内容,按钮现在将在主图像视图中循环显示图像。如果到达最后一张图像,它将自动回绕。