iphone – 如何在ios中使用URL和NSString在UIImageView上显示图
发布时间:2020-12-14 19:59:12  所属栏目:百科  来源:网络整理 
            导读:我想使用URL和NSString在UI ImageView上显示图像.我无法显示图像. 我的代码是: UIImageView *view_Image = [[UIImageView alloc]initWithFrame:CGRectMake(view_Image_Pos_X,view_Image_Pos_Y,179,245)];view_Image.backgroundColor = [UIColor greenColor]
                
                
                
            | 
                         
 我想使用URL和NSString在UI 
 ImageView上显示图像.我无法显示图像. 
  
  
我的代码是: 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_Img_FULL),然后传递到如下图像: UIImage * image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:url_Img_FULL]]]; //不工作 我想从“url_Img_FULL”(即:两个网址的组合)图像将显示. 解决方法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]]]; 
 试试这个. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!  | 
                  
