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!
(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.
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.
[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.
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.
发布评论
评论(7)
好吧,伙计们,如果你愿意付钱的话。这个工具将解决您的所有问题。您可以导入 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/
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.
如果您愿意从 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
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.
SVGgh 包含一个类 SVGPathGenerator,它将 SVG 路径转换为 CGPathRef:
您可以使用它来执行以下操作 :正是您所要求的。
[Swift 3 更新] 如果您想要一个纯粹的 Swift 解决方案。我的(正在进行中)Scalar2D 库在 CGPath 上有一个扩展,它创建了一个来自 SVG 路径的 CGPath。
SVGgh contains a class, SVGPathGenerator, which will convert an SVG path to a CGPathRef:
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.
该解决方案是将 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
将 SVG 添加到 NSView 的 Oneliner:
SVGLib for swift: https://github.com/eonist/swift -utils
Oneliner that adds an SVG to an NSView:
SVGLib for swift: https://github.com/eonist/swift-utils