gpt4 book ai didi

ios - 在 UIImage imageNamed 中使用外部图像

转载 作者:可可西里 更新时间:2023-11-01 04:44:51 30 4
gpt4 key购买 nike

我正在从网络 Apple.png 和 Apple@2x.png 下载两张图片。我想使用 [UIImage imageNamed:@"Apple.png"] 以便它可以使用内置功能来检测它是否应该显示 Apple.png 或 Apple@2x.png。

现在我在哪里存储这些图像?我在文档中阅读了以下内容:

The name of the file. If this is the first time the image is being loaded, the method looks for an image with the specified name in the application’s main bundle.

啊所以应用程序的主包是要走的路。这是我的代码的样子:

NSString      *directory   = [[NSBundle mainBundle] bundlePath]; 
NSString *path = [directory stringByAppendingPathComponent:imageName];
NSFileManager *fileManager = [NSFileManager defaultManager];

[fileManager createFileAtPath:path contents:dataFetcher.receivedData attributes:nil];

我检查了文件是否在路径的文件夹中创建并且是正确的。我还在我的项目文件中拖了一个 Example.png 只是为了看看它是否存储在同一个文件夹中,这也是正确的。

但是,[UIImage imageNamed:@"Apple.png"] 仍然无法获取图像。

最佳答案

您不能对应用程序下载的图片使用 UIImage'a +imageNamed: 方法。该方法确实在应用程序包中查找图像,但不允许您的应用程序在运行时更改其自身的包。

关于ios - 在 UIImage imageNamed 中使用外部图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4754551/

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