Search code examples
swiftclipboarduifonttext-styling

How to build a font generator in iOS Swift and allowing pasting to clipboard


I'm now building a listview to display fonts from the UIFonts framework. However, for using UIPasteboard.general.string, the fonts are not copied to the clipboard and only the plain text is transferred.

I've tried including the MobileCoreServices framework and use kUTTypeRTF to implement it. But there is no detailed documentation on it.

May I know how can I build a custom font list and allowing the text be selected and pasted with its font styling onto the other applications (like Notes or Facebook post), just like the font generator hosted online?

I'm now working on the two following UIFonts, but I'm not able to keep its formatting while pasting from the clipboard.

let fonts: [String] = ["BodoniSvtyTwoOSITCTT-Book", "ChalkboardSE-Regular"]

Solution

  • You cannot copy-paste text with a font on your iPhone.

    FancyLetters also cannot do this. It just shows you characters that look like they are printed.

    For example, the letter "A" has variations: "𝓐", "𝒜", "𝔸". But this is not font-altered text, StackOverflow does not allow it either. These are characters from Unicode table. They are the same characters as "A" or "B", except that without special modifiers the keyboard will not print them for you, e.g. SHIFTOPTIONK = .

    Any font is superimposed over Unicode characters.

    I recommend you to read an excellent article Emoji under the hood. It's about how emoji are drawn on devices, but it also explains a lot about the construction of characters and how they are rendered on different devices.