[英]Load image from Foursquare URL to UIImageView
I have a table view where I list the nearest venues with the Foursquare API. 我有一个表格视图,其中使用Foursquare API列出了最近的场所。 All fine but now I want to add the category icon. 很好,但现在我想添加类别图标。 I can get the URL of that image but how to display it on a UIImageView? 我可以获取该图像的URL,但是如何在UIImageView上显示它呢?
I tried open that URL from chrome but wasn't possible " https://ss1.4sqi.net/img/categories_v2/food/coffeeshop.png " 我尝试从Chrome打开该URL,但无法实现“ https://ss1.4sqi.net/img/categories_v2/food/coffeeshop.png ”
{
icon = {
prefix = "https://ss1.4sqi.net/img/categories_v2/food/coffeeshop_";
suffix = ".png";
};
id = 4bf58dd8d48988d1e0931735;
name = "Coffee Shop";
pluralName = "Coffee Shops";
primary = 1;
shortName = "Coffee Shop";
}
Append size to suffix in response from available sizes like 64
.Refer more from fourSquare
docs .You need to add size with sufix 可以将大小附加到后缀以响应可用的大小(例如64
参考fourSquare
文档中的更多fourSquare
。您需要使用fourSquare
添加大小
Combine prefix with a size (32, 44, 64, and 88 are available) 将前缀与大小结合使用(可以使用32、44、64和88)
https://ss1.4sqi.net/img/categories_v2/food/coffeeshop_64.png https://ss1.4sqi.net/img/categories_v2/food/coffeeshop_64.png
You can use 您可以使用
NSString *imgUrl = [NSString stringWithFormat:@"%@/%@/%@", response[@"icon"][@"prefix"],@"64",response[@"icon"][@"suffix"]]
add 64
as it repersents size 64*64 添加64
因为它代表尺寸64 * 64
If you want to set on imageview
than use 如果要在imageview
上设置而不是使用
NSData * imageData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: imgUrl]];
UIImageView *yourImageView = [[UIImageView alloc] initWithImage:[UIImage imageWithData: imageData]];
This is synchrounous so it will block main thread
use other asynchrounous options 这是同步的,因此它将阻止main thread
使用其他异步选项
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.