如何在ios中使用URL和NSString在UIImageView上显示图像? [英] How to display image on UIImageView using URL and NSString in ios?
本文介绍了如何在ios中使用URL和NSString在UIImageView上显示图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用URL和 NSString
在 UIImageView
上显示图像。我无法显示图片。
I want to display image on UIImageView
using URL and NSString
. I am unable to show image.
我的代码是:
UIImageView *view_Image = [[UIImageView alloc]initWithFrame:CGRectMake(view_Image_Pos_X, view_Image_Pos_Y, 179, 245)];
view_Image.backgroundColor = [UIColor greenColor];
view_Image.tag = img;
view_Image.userInteractionEnabled=YES;
view_Image.autoresizesSubviews = YES;
view_Image.alpha = 0.93;
[self.view addSubview:view_Image];
这就是我想要的:
if (img == 0) {
NSString *url_Img1 = @"http://opensum.in/app_test_f1/;";
NSString *url_Img2 = @"45djx96.jpg";
NSString *url_Img_FULL = [NSString stringWithFormat:@"%@%@", url_Img1,url_Img2];
NSLog(@"Show url_Img_FULL: %@",url_Img_FULL);
NSURL *url_img = [NSURL URLWithString:url_Img_FULL];
NSLog(@"Show: url_img %@",url_img);
// Here below line working perfectly and image is showing
view_Image.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://opensum.in/app_test_f1/45djx96.jpg"]]]; // working code
但我不想要这个我想要连续两个url make one url(即; url_Img_FULL)然后传递给如下图像:
but i dont want this i want to concatanate two url make one url(ie;url_Img_FULL) and then pass to an image like below:
UIImage * image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:url_Img_FULL] ]]; //不工作
我想从url_Img_FULL(即:两个网址的组合)图像将显示。
您还可以检查网址是否正常工作。
有什么想法?
I Want from "url_Img_FULL" (ie: combination of two url) The image will show. You can check also the url is working properly. Any idea?
推荐答案
NSString *url_Img1 = @"http://opensum.in/app_test_f1";
NSString *url_Img2 = @"45djx96.jpg";
NSString *url_Img_FULL = [url_Img1 stringByAppendingPathComponent:url_Img2];
NSLog(@"Show url_Img_FULL: %@",url_Img_FULL);
view_Image.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:url_Img_FULL]]];
试试这个。
这篇关于如何在ios中使用URL和NSString在UIImageView上显示图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文