【问题标题】:how to convert a URL string into an UIImage [duplicate]如何将 URL 字符串转换为 UIImage [重复]
【发布时间】:2015-02-21 07:14:21
【问题描述】:
NSString *imageName = [NSString stringWithFormat:@"%@UploadedImages/%@",appDel.serverUrl,[[sCatArray objectAtIndex:indexPath.row] objectForKey:@"SubCategoryIcon"]];

在 imageName 字符串中获取下面给出的字符串。如何将这些 url 转换为图像

http://appliicdev.xtechnologies.com/iapp/UploadedImages/5bc77bdd-3eaf-4491-813a-5aedcbfbba41.jpg

谢谢

【问题讨论】:

标签: ios objective-c xcode


【解决方案1】:

您可以从UIImage 使用imageWithData。喜欢,

UIImage *image =[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:imageName]]];

【讨论】:

    【解决方案2】:

    试试这个:

    NSString *imageName = [NSString stringWithFormat:@"%@UploadedImages/%@",appDel.serverUrl,[[sCatArray objectAtIndex:indexPath.row] objectForKey:@"SubCategoryIcon"]];
    UIImage *imgObj = [UIImage imageWithData: [NSData dataWithContentsOfURL: [NSURL URLWithString:imageName]]];
    _yourImgView.image=imgObj;
    

    【讨论】:

      【解决方案3】:

      你的代码很好

      改变这一行

      NSString *imageName = [NSString stringWithFormat:@"%@UploadedImages/%@",appDel.serverUrl,[[sCatArray objectAtIndex:indexPath.row] objectForKey:@"SubCategoryIcon"]];
      

      进入你的URL 包含/UploadedImages/

      NSString *imageName = [NSString stringWithFormat:@"%@/UploadedImages/%@",appDel.serverUrl,[[sCatArray objectAtIndex:indexPath.row] objectForKey:@"SubCategoryIcon"]];
      
      yourimageName.image =[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:imageName]]];
      

      您是否需要快速加载UIImage 使用

      1. Asynchronous FreeLoader

      2. SDWebImage

      当我在浏览器中尝试您的图像时,它会显示错误,因此请检查一次 path is valid or not 否则 your image name is valid or not

      【讨论】:

        猜你喜欢
        • 2022-01-06
        • 1970-01-01
        • 1970-01-01
        • 2014-05-10
        • 1970-01-01
        • 2017-11-11
        • 2012-04-13
        • 2021-06-17
        • 2012-10-22
        相关资源
        最近更新 更多