For UILabel
, I can set the system font as:
label.font = UIFont.systemFontOfSize(18, weight: UIFontWeightMedium)
For CATextLayer
, is there a similar way to set the system font instead of giving the font name directly?
textLayer = CATextLayer()
textLayer.font = ??? // instead of CTFontCreateWithName("HelveticaNeue-Bold", 18, nil)
The answer is no, but if you are bored about type system font names, you can wrap in a simple function:
For custom fonts, I like to enumerate the font family like this:
The usage is very simple
This is useful to keep everything typed strongly, so you will get autocompletion for free and avoid typos.