如何将URL字符串转换为UIImage

时间:2014-12-23 06:46:44

标签: ios objective-c xcode

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

由于

3 个答案:

答案 0 :(得分:3)

您可以使用imageWithData中的UIImage。像,

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

答案 1 :(得分:2)

你的编码很好

更改此行

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

进入bz ur 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

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

    enter image description here

答案 2 :(得分:-1)

试试这个:

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;