I feel like UIFont’s read-only properties go forgotten easily. When you create a new font object, five measurement properties will be evaluated based on the set point-size.
Note that most of these will be floats and should be rounded up or down before using in any layout functions.
Unless you’re drawing directly with the text, you’ll probably only ever need to use lineHeight (it’s the property multiplied by lineHeightMultiple in NSParagraphStyle). pointSize is almost useless; it tells you nothing about the actual pixels measurements.
I used to find myself randomly guessing a lot of magic numbers when it came to laying out paragraphs. The biggest issue I had was text clipping with small `lineHeightMultiples` — I figured that out in my last post.
`NSParagraphStyle` is much better documented in the header file then its actual documentation (⌘-click an attribute to view). In lieu of that, I made a quick cheatsheet for everybody to understand what’s possible.
Funnily enough, sometimes the best way to explain text is with an image.
It all makes so much sense now. My next post explains `UIFont`.
Setting paragraph attributes on an `NSAttributedString` can be frustrating. Without a diagram, knowing what and how to set metrics isn’t super intuitive. You’ll end up fussing with all of them until it looks about right.
The most frustrating is leading (pronounced /ˈlɛdɪŋ/ as in the metal used in printing presses). `lineHeightMultiple` works well — until your texts starts to get clipped.
var lineHeightMultiple: CGFloat
The natural line height is multiplied by this factor (if positive) before being constrained by minimum and maximum line height.
Easy enough, 1 will keep the current height of the lines, greater than 1 will increase it, and less than 1 will decrease it. Decreasing your line height with a value less than 1 decreases your top line’s height, too, of course. …