xcode 图像处理库_Xcode中的SVG资产用于单比例图像

xcode 图像处理库

Xcode 12 introduced support for using Scalable Vector Graphic (SVG) image assets in iOS, macOS, and iPadOS. It’s one of those changes that you might have missed during WWDC 2020 as it’s quite a small addition.

Xcode 12引入了对在iOS,macOS和iPadOS中使用可缩放矢量图形(SVG)图像资产的支持。 这是您在WWDC 2020期间可能错过的那些更改之一,因为它只是很小的一部分。

Up until Xcode 12, we were able to use single scale resources by using PDF assets. It takes away the need to generate individual images for each scale using the @1x, @2x, and @3x postfix. This saves you time and also takes away potential mistakes like accidentally generating a @3x asset with the @1x image size (we all did that once, right?).

直到Xcode 12,我们都可以通过使用PDF资产来使用单比例资源。 无需使用@ 1x,@ 2x和@ 3x后缀为每个比例生成单独的图像。 这可以节省您的时间,还可以避免潜在的错误,例如意外生成具有@ 1x图像大小的@ 3x资源(我们都这样做过一次,对吧?)。

什么是可伸缩矢量图形资产? (What is a Scalable Vector Graphic asset?)

Scalable Vector Graphics, also known as SVG, defines two-dimensional graphics defined in Extensible Markup Language (XML). It’s mostly used for icons and symbols and allows platforms to scale up the asset for the current active resolution.

可伸缩矢量图形,也称为SVG,定义了在可扩展标记语言(XML)中定义的二维图形。 它主要用于图标和符号,并允许平台按当前有效分辨率扩展资产。

什么时候应该使用单一规模资产? (When should I use Single Scale Assets?)

SVG assets can not be seen as a replacement for all your assets. Rich assets like images with lots of details should still be defined as individual scales. If you have a logo, icons, or symbols, you can most likely look into replacing them with an SVG asset.

SVG资产不能视为您所有资产的替代品。 诸如具有大量细节的图像之类的丰富资产仍应定义为单个比例。 如果您有徽标,图标或符号,则很可能会考虑将其替换为SVG资产。

支持平台 (Supported platforms)

It’s important to point out that SVGs are only supported on macOS 10.15 or later, iOS 13 or later, and iPadOS or later. If your app supports any older version you should not use single scale SVGs.

重要的是要指出,SVG仅在macOS 10.15或更高版本,iOS 13或更高版本以及iPadOS或更高版本上受支持。 如果您的应用支持任何旧版本,则不应使用单比例SVG。

考虑使用SFSymbols作为替代 (Considering SFSymbols as an Alternative)

Before you start replacing all your assets with SVGs you might want to consider using SFSymbols instead. SFSymbols have the same platform version availability and are available as system images. This takes away some extra space in your app bundle.

在开始用SVG替换所有资产之前,您可能需要考虑使用SFSymbols。 SFSymbol具有相同的平台版本可用性,并且可以作为系统映像使用。 这会占用应用程序捆绑包中的一些额外空间。

如何在Xcode中使用SVG? (How can I use an SVG in Xcode?)

Using SVGs in Xcode is fairly simple. You simply drag the file into your Assets Catalog after which you have to change the Scales option to “Single Scale:”

在Xcode中使用SVG非常简单。 您只需将文件拖到“资产目录”中,然后就必须将“比例”选项更改为“单比例:”

Using an SVG Image Asset in Xcode
Using an SVG Image Asset in Xcode
在Xcode中使用SVG图像资产

After that, you can use your SVG Image Asset just like any other asset.

之后,您可以像使用其他资产一样使用SVG图像资产。

PDF与SVG资产 (PDF vs SVG assets)

Single scale PDFs are introduced in Xcode 6 and are supported since iOS 8 and OS X 10.9. This could already be a reason to use PDFs instead of SVG if your app is supporting targets lower than iOS 13, iPadOS 13, or macOS 10.15. Both PDF and SVG have the same outcome when used as single scale assets.

Xcode 6中引入了单比例PDF,自iOS 8和OS X 10.9开始支持单比例PDF。 如果您的应用支持低于iOS 13,iPadOS 13或macOS 10.15的目标,这可能已经是使用PDF而不是SVG的原因。 将PDF和SVG用作单一比例资产时,其结果相同。

考虑资产的文件大小 (Considering the file size of assets)

Comparing the file size of the same asset exported as SVG or PDF results in different winners based on the type of image, resource details, and export configuration. If you’re focused on having a small app size you might want to consider exporting to both PDF and SVG to be able to pick the smallest version.

根据图像类型,资源详细信息和导出配置,比较以SVG或PDF格式导出的同一资产的文件大小会导致不同的获胜者。 如果您专注于缩小应用程序尺寸,则可能需要考虑同时导出到PDF和SVG,以便能够选择最小的版本。

In most cases though, SVGs are smaller in size. On top of that, you can also find lots of resources on the web for optimizing SVGs as they’re a popular type of asset to use during web development.

但是,在大多数情况下,SVG的尺寸较小。 最重要的是,您还可以在网络上找到许多资源来优化SVG,因为它们是在Web开发过程中使用的一种流行资产。

结论 (Conclusion)

SVG support is a great addition introduced in Xcode 12 during WWDC 2020. It allows single scale assets with an often smaller size resource file. SVGs are not always the right choice as they’re only supported from iOS 13 and later, iPadOS 13 and later, and macOS 10.15 and later. In those cases, you can fall back on using PDFs instead.

SVG支持是WWDC 2020期间Xcode 12中引入的一项重要功能。它支持单比例资产,其资源文件通常较小。 SVG并非总是正确的选择,因为只有iOS 13和更高版本,iPadOS 13和更高版本以及macOS 10.15和更高版本才支持SVG。 在这种情况下,您可以转而使用PDF。

翻译自: https://medium.com/better-programming/svg-assets-in-xcode-for-single-scale-images-b4f8e2249aa5

xcode 图像处理库

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值