从URL加载时应如何处理视网膜/正常图像?

编程入门 行业动态 更新时间:2024-10-17 23:26:29
本文介绍了从URL加载时应如何处理视网膜/正常图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我了解如何以编程方式从网址为我的应用加载图片,而不是将其打包在应用内,但如何处理1x vs 2x问题?如果需要,我可以从外部源提供这两个版本,但在设置UIImage时如何处理?

I understand how to programmatically load images for my app from a URL instead of packaging them within the app but how do I handle the 1x vs 2x issue? I can serve both versions from the external source if need be but how do I handle that when setting the UIImage?

推荐答案

我'我很确定你无法以自动方式远程加载@ 2x图像文件。您将必须测试视网膜显示,然后获得适当的图像,如下所示:

I'm pretty sure you cannot load @2x image files remotely in an automated way. You will have to test for the retina display and then get the appropriate image(s), like so:

UIImage *image; if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] && [[UIScreen mainScreen] scale] == 2){ // @2x NSURL *imageURL = [NSURL URLWithString:@"www.example/images/yourImage@2x.png"]; NSData * imageData = [NSData dataWithContentsOfURL:imageURL]; image = [UIImage imageWithData:imageData]; } else { // @1x NSURL *imageURL = [NSURL URLWithString:@"www.example/images/yourImage.png"]; NSData * imageData = [NSData dataWithContentsOfURL:imageURL]; image = [UIImage imageWithData:imageData]; } UIImageView *yourImageView = [[UIImageView alloc] initWithImage:image];

更多推荐

从URL加载时应如何处理视网膜/正常图像?

本文发布于:2023-11-26 22:59:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1635554.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视网膜   时应   如何处理   图像   加载

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!