如何将 SVG 导入/解析到 UIBezierpaths、NSBezierpaths、CGPaths 中?

发布于 2024-10-27 20:27:12 字数 1436 浏览 6 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

金橙橙 2024-11-03 20:27:12

好吧,伙计们,如果你愿意付钱的话。这个工具将解决您的所有问题。您可以导入 svg 或 psd,系统会为您生成代码。我用过它,效果太棒了!

http://www.paintcodeapp.com/

Alright folks, if you're willing to pay for it. This tool will solve all your issues. You can import svg or psd and will produce the code for you. I've used it and it is amazing!

http://www.paintcodeapp.com/

断桥再见 2024-11-03 20:27:12

ObjectiveC 中有一个开源 SVG 库,专门用于 iOS(和 OS X,尽管 OS X 构建有点落后):

https://github.com/SVGKit/SVGKit/

(我从今年年初开始就在 iOS 项目上使用这个,效果很好)

2018 更新 :现已支持 OSX,并且 SVGKit 可以快速且准确地呈现大多数 SVG。缺点是,高级文本功能并不全部受支持(例如,支持渐变填充,但不支持复杂的文本布局)。

截至 2012 年初,它还没有 100% 实现 SVG 规范,但有很多人正在努力实现它。

There's an open-source SVG library in ObjectiveC, specifically for iOS (and OS X, although the OS X build is a bit behind):

https://github.com/SVGKit/SVGKit/

(I've been using this on iOS projects since the start of this year, it works well)

2018 update: OSX support is now in, and SVGKit renders most SVG's fast + accurately. On the downside, advanced text features aren't all supported (e.g. yes to gradient-fill, but no to complex text-layout).

As of early 2012, it's not a 100% implementation of the SVG spec, but there's a lot of people working on getting it there.

浅暮の光 2024-11-03 20:27:12

如果您愿意从 JS 到 ObjC 进行一些翻译,那么您可能会发现这个项目很有帮助:

https:// /github.com/thelonious/svg-2d

特别是,path.js 文件包含一个 parseData 方法,负责处理相对和绝对路径命令。

https://github.com/thelonious/svg-2d /blob/master/shapes/path/Path.js

我应该提一下,我几年前编写了这段代码,但我已将其翻译为 Java 和 C# 并已在专业产品中使用(无法共享该代码,不幸的是)并且它似乎在这些环境中也运行良好。

华泰
凯文

If you're willing to do some translation from JS to ObjC, then you might find this project helpful:

https://github.com/thelonious/svg-2d

Particularly, the path.js file which includes a parseData method, taking care of relative and absolute path commands.

https://github.com/thelonious/svg-2d/blob/master/shapes/path/Path.js

I should mention that I wrote this code years ago, but I have translated it to Java and C# and have used in professional products (can't share that code, unfortunately) and it seemed to work well in those environments as well.

HTH
Kevin

八巷 2024-11-03 20:27:12

Mac App Store 上的 Sketch 3 擅长编辑(可以比 PaintCode 更好),然后导出为 SVG 到 PaintCode。

要从 PaintCode 返回 Sketch,另存为 PDF 并导入即可

https: //itunes.apple.com/gb/app/sketch-3/id852320343?mt=12

确保两者中的画布大小设置为相同,并且在您的视图范围内,否则您需要缩放上下文。

Sketch 3 on Mac App Store is good at editing (can be better than PaintCode) and then exporting as SVG to PaintCode.

To get from PaintCode back to Sketch save as PDF and imports ok

https://itunes.apple.com/gb/app/sketch-3/id852320343?mt=12

Make sure canvas size in both is set to the same and in your views bounds else youll need to scale the context.

舂唻埖巳落 2024-11-03 20:27:12

SVGgh 包含一个类 SVGPathGenerator,它将 SVG 路径转换为 ​​CGPathRef:

+(CGPathRef) newCGPathFromSVGPath:(NSString*)anSVGPath whileApplyingTransform:(CGAffineTransform)aTransform;

您可以使用它来执行以下操作 :正是您所要求的。

[Swift 3 更新] 如果您想要一个纯粹的 Swift 解决方案。我的(正在进行中)Scalar2D 库在 CGPath 上有一个扩展,它创建了一个来自 SVG 路径的 CGPath。

SVGgh contains a class, SVGPathGenerator, which will convert an SVG path to a CGPathRef:

+(CGPathRef) newCGPathFromSVGPath:(NSString*)anSVGPath whileApplyingTransform:(CGAffineTransform)aTransform;

You can use it to do exactly what you request.

[Swift 3 Update] If you want a pure Swift solution. My (in progress) Scalar2D library has an extension on CGPath that creates a CGPath from an SVG path.

蓝咒 2024-11-03 20:27:12

该解决方案是将 SVG 路径字符串直接转换为 UIBezierPath。它非常适合我的应用程序,我必须将美国绘制为 UIView。

https://github.com/ap4y/UIBezierPath-SVG

This solution is a straight conversion of an SVG path string to UIBezierPath. It worked great for my app where I had to draw the united states as a UIView.

https://github.com/ap4y/UIBezierPath-SVG

时间海 2024-11-03 20:27:12

将 SVG 添加到 NSView 的 Oneliner:

addSubView(SVGParser.svg(FileParser.xml(~/Desktop/test.svg)))

SVGLib for swift: https://github.com/eonist/swift -utils

Oneliner that adds an SVG to an NSView:

addSubView(SVGParser.svg(FileParser.xml(~/Desktop/test.svg)))

SVGLib for swift: https://github.com/eonist/swift-utils

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文