I’d like to add custom fonts at runtime to an IOS app and use it in either a editable textarea or a UIWebView with contentEditable=”on”.
I know how you bundle custom fonts at compile time, but I need to do this at runtime.
Is any of these alternatives possible:
- Download fonts over the Internet and store within the apps documents folder?
- Reference external fonts using http addresses?
- Transfer fonts via iTunes?
There’s been lot’s of improvements to labels and rich text editing in iOS6, and I was hoping that custom font support has improved as well.
Answering my own question.
I have not found a way to do this with a native textarea in iOS without registering the font in the plist file.
How ever, the UIWebView does support @font-face declarations and .ttf files. The trick is to create a NSURL that points to the font stored in the Documents folder and then tell the web view to use this by using [webView stringByEvaluatingJavaScriptFromString].
In my first tests I did something like this:
My view controller:
In my web page: