-2

我在 FTP 中有一些图像,我需要在我的 iphone 应用程序的图像视图中显示这些图像,是否可以在不下载图像的情况下加载图像,只需将 FTP 图像 URL 加载到图像视图?

4

3 回答 3

1

有一个很酷的库叫做SDWebImage。它异步下载图像,因此您的应用程序保持响应。它向 UIImageView 添加了一个类别,因此您只需将 url 传递给 ImageView,一切都会自动为您完成。它也适用于ftp://url。

像这样的东西应该工作:

UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f,0.0f,50.0f,50.0f)];

[imageView setImageWithURL:[NSURL URLWithString:@"ftp://example.com/path/image.jpeg"]
               placeholderImage:[UIImage imageNamed:@"placeholder.png"]];

您还可以指定在未下载图像时显示的占位符。

于 2012-12-07T11:13:35.823 回答
1

查看 Apple 的简单 FTP 示例

一旦您有权访问 FTP 服务器:

NSURL *theUrl = [NSURL URLWithString:@"ftp://userid:password@your.server/image.png"];
UIImage *newImage = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:url]];
UIImageView *newImageView = [UIImageView imageViewWithImage:newImage];

请记住,此过程需要时间,因此请在后台线程上进行工作以确保应用程序的响应能力。

于 2012-12-07T11:10:10.047 回答
0

是的,您可以只使用 FTP URL 来加载图像。

于 2012-12-07T11:04:16.027 回答