你能从 PDF 数据创建 UIImage 吗?

Can you create an UIImage from PDF data?

我正在加载一个远程 PDF 文件并尝试将其转换为 UIImage(用于在 UIImageView 中显示),但我很惊讶它似乎不起作用。即使 Asset Catalog 中的本地 PDF 文件工作正常,除此之外不支持 PDF 吗?

编辑:我发现 https://developer.apple.com/library/archive/documentation/2DDrawing/Conceptual/DrawingPrintingiOS/LoadingImages/LoadingImages.html 这表明不,PDF 不起作用。所以这给我留下了一个问题:why/how 它对资产目录中的本地文件有效吗?为什么或有何不同?

回答您的"Why or how is that different?"问题...

将 PDF 文件添加到资产目录时,Xcode 在构建时呈现 @1x, @2x and @3x 个版本。

可以 select Preserve Vector Data 得到 pdf "rendered on-the-fly." 这通常效果很好,尽管如果你有很多 pdf 和您对它们进行了大量操作,可能 会降低性能。