繁体   English   中英

将下载的图像从URL设置为Imageview-IoS

[英]Set a downloaded image to Imageview from url - IoS

我有一个网址,点击它会下载图片。 我想将图像设置为imageview。 目前已尝试过此操作,但无法加载图像。 谁能建议我要去哪里错了。

提前致谢!

NSURL *url1 = [NSURL URLWithString:@"http://farm4.staticflickr.com/3695/9258420948_566a38bfdb_q_d.jpg"];
pic1.image = [UIImage imageWithCIImage:[CIImage imageWithContentsOfURL:url1]];

您要在UIImageView上使用AFNetworking的类别:

[myImageView setImageWithURLRequest:urlRequest placeholderImage:[UIImage imageNamed:@"placeholder.png"] success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
    myImageView.image = image;
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
    NSLog(@"Request failed with error: %@", error);
}];

值得为此通话使用AFNetworking。 (AFNetworking还为您提供了一个占位符图像,它还缓存了网络图像,因此后续调用将使用缓存来快速响应。)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM