1

Is there a way/class to take a UILabel and turn it into any kind of vector ? for instance SVG, or some kind of bezier path ?

If it can be done with a UIImage (can it ? ) I can simply turn the text first to an image.

A similar effect happens in Illustrator and it's called tracing , or for text "create outlines" .

Curnelious
  • 1
  • 16
  • 76
  • 150
  • I have no idea how to do that, but I would try to [generate PDF content](https://developer.apple.com/library/content/documentation/2DDrawing/Conceptual/DrawingPrintingiOS/GeneratingPDF/GeneratingPDF.html) first, and then find a library that converts PDF to SVG (if that even exists). – deadbeef Jun 23 '17 at 12:54

1 Answers1

2

Take a look at the "Getting Glyph Data" section in Apple's CTFont docs here: https://developer.apple.com/documentation/coretext/ctfont-q6r

A quick search for CTFontCreatePathForGlyph swift example should get you practical example code to work with.

DonMag
  • 69,424
  • 5
  • 50
  • 86
  • Wow it is doable. Thanks a lot. – Curnelious Jun 23 '17 at 13:34
  • Turns out that's not an SVG output, but a UIBezierPath . To turn UIBezierPath to SVG is a completely different think which I don't know how to do. – Curnelious Jun 29 '17 at 17:23
  • Is your end goal to generate SVG files? If so, there is plenty of documentation out there for doing that. Here is one place to start: https://stackoverflow.com/questions/22202741/drawing-with-cgpath-to-svg-output – DonMag Jun 29 '17 at 17:40
  • Thanks, yes SVG. have seen this one, its an objective c class, dont know how to rewrite it to swift – Curnelious Jun 29 '17 at 17:43
  • There are a number of "Obj-C to Swift" converters out there. If you really can't follow the code, give one of those a try. Ought to at least get you on your way. – DonMag Jun 29 '17 at 17:45
  • The code is huge, it would take a long time to change this. I was thinking there is a quick solution as bezier is similar to SVG. If you hear let me know :) – Curnelious Jun 29 '17 at 17:47
  • The GitHub repo pointed to in that post is a Framework for iOS. Sounds pretty much like what you're asking for. Unless... can you be a little more clear about what you want to do? – DonMag Jun 29 '17 at 17:51
  • I want to take a UIBezierPath, and produce an SVG file out of it, using Swift. If you know how to do this using this one I will be really grateful. I just asked about it here, https://stackoverflow.com/questions/44831340/uibezierpath-to-svg – Curnelious Jun 29 '17 at 17:55
  • The person who put together that Framework *outlined exactly how to save a path to a file in SVG format*. What more do you need? – DonMag Jun 29 '17 at 17:58
  • Search where ? in the guy's library? it's not there. Well if you have the part of code just write it, I am not good at guessing. I'v read all of his readme. – Curnelious Jun 29 '17 at 18:09
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/147972/discussion-between-donmag-and-curnelious). – DonMag Jun 29 '17 at 18:12