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

我知道如何以编程方式从URL加载我的应用程序的图像,而不是将它们打包在应用程序中,但是如何处理1x vs 2x问题? 如果需要,我可以从外部来源提供两个版本,但在设置UIImage时如何处理?

我很确定你不能以自动方式远程加载@ 2个图像文件。 你将不得不testing视网膜显示,然后得到适当的图像,如下所示:

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