我有一个表格视图,我用Foursquare API列出最近的场地。一切都很好,但现在我想添加类别图标。我可以获取该图像的URL,但如何在UIImageView上显示它?
我尝试从Chrome打开该网址但是不可能" 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";
}
答案 0 :(得分:2)
根据64
等可用尺码附加后缀大小。请参阅fourSquare
docs中的更多内容。您需要使用sufix添加尺寸
将前缀与大小相结合(32,44,64和88可用)
https://ss1.4sqi.net/img/categories_v2/food/coffeeshop_64.png
您可以使用
NSString *imgUrl = [NSString stringWithFormat:@"%@/%@/%@", response[@"icon"][@"prefix"],@"64",response[@"icon"][@"suffix"]]
添加64
,因为它的大小为64 * 64
如果您想设置imageview
而不是使用
NSData * imageData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: imgUrl]];
UIImageView *yourImageView = [[UIImageView alloc] initWithImage:[UIImage imageWithData: imageData]];
这是同步的,所以它会阻止main thread
使用其他异步选项