gpt4 book ai didi

ios - 从 Foursquare URL 加载图像到 UIImageView

转载 作者:行者123 更新时间:2023-11-28 19:58:42 24 4
gpt4 key购买 nike

我有一个表格 View ,其中我使用 Foursquare API 列出了最近的场所。很好,但现在我想添加类别图标。我可以获得该图像的 URL,但如何在 UIImageView 上显示它?

我尝试从 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";
}

最佳答案

将大小附加到后缀以响应可用大小,例如 64。更多信息请引用 fourSquare docs .你需要添加大小后缀

Combine prefix with a size (32, 44, 64, and 88 are available)

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]];

这是同步的,所以它会阻止主线程使用其他异步选项

关于ios - 从 Foursquare URL 加载图像到 UIImageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25125766/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com