我喜欢将 .jpg 或 .png 文件转换为可以在 UIImageView 中显示的 .svg 格式。有没有办法在 Objective-C 中做到这一点?
最佳答案
你 shouldn't在 Xcode 中使用 SVG 图像:
it is recommended that you use PNG or JPEG files for most images in your app. Image objects are optimized for reading and displaying both formats, and those formats offer better performance than most other image formats. Because the PNG format is lossless, it is especially recommended for the images you use in your app’s interface.
此外,还有一个 SVGKit根据许多开发者的说法是 buggy所以使用它需要您自担风险。
SVG 是一种基于 XML 的矢量,在 Xcode 中您也可以使用矢量,但使用 PDF 格式并遵循 this教程。
简而言之:
- 使用@1x Assets 生成 PDF(在编译期间它将生成 @2 和 @3)
- 将比例因子设置为单个向量:
- 将您的 PDF 拖放到通用部分
通过名称引用您的图像,就像任何 PNG 文件一样
[UIImage imageNamed:@”Home”]
此外,stackoverflow(可能)related回答
关于ios - 如何在 iOS 中将 jpg 或 png 转换为 svg?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39722740/