I've been scouring the Internet for a while now for information on how one can alter the letter-spacing/kerning of a font within UIKit.
My fear is, that like using your own custom fonts, you simply can't. Which would be terrible news.
I know Apple is protecting us from bad design with these constraints, but they're also preventing us from implementing really great design too.
What do people suggest I do?
Use the font with the standard kerning, people probably wouldn't notice the difference anyway.
Find someone's hacked class to get the look the user deserves after parting with their hard earned cash.
Use the method that I've somehow overlooked, and do it with UIKit, pledging my eternal gratitude to the person who imparts this hidden nugget of knowledge.
You may be able to do what you need using Quartz 2D. Specifically, the
CGContextSetCharacterSpacing
property can control spacing between letters. I'm not sure about kerning though.Quartz 2D Programming Guide: Text
The main problem of CGContextShowText methods - they are diaplays only ASCII strings. To display UTF strings you need to map your string symbols to glyphs and show glyphs.
I landed here from Google trying to do the same with UITextField. I implemented something that'll work generically for UILabel below.
Then to use it, just set up the label in viewDidLoad or something
I tried it with UITextField, but unfortunately it only adds the character spacing after the user has edited the field. -drawTextInRect is only called after the -textFieldShouldEndEditing delegate method. From other forums some suggested this was because UITextField needs to know the rendering of the font in order to display the cursor. Never found a solution for that piece...
I've extended UILabel to change the character spacing. This should work out the box and pulls font, text, color etc from the UILabel itself (proper coding!).
You may notice I draw the text twice, first with clear color. This is to auto center the text in the label. Whilst this may be inefficient - isn't it nice to be auto centered?
Enjoy!
The accepted answer lost a lot of the formatting, and user363349's answer mostly worked for me but text alignment wasn't working. I modified the code to fix that: