【问题标题】:how to convert a URL string into an UIImage [duplicate]如何将 URL 字符串转换为 UIImage [重复]
【发布时间】:2015-02-21 07:14:21
【问题描述】:
【问题讨论】:
标签:
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 使用
Asynchronous FreeLoader
SDWebImage
当我在浏览器中尝试您的图像时,它会显示错误,因此请检查一次 path is valid or not 否则 your image name is valid or not