Easier UIFont usage
1 min read
In a previous post I was writing about improving working with UIFont and now I’d like to take it one step further in regards with having a quick and easy way to set fonts, if you use a single typeface (font family):
extension UIFont {
static func regular(_ size: CGFloat) -> UIFont {
return .systemFont(ofSize: size, weight: .regular) // Or any other font.
}
static func medium(_ size: CGFloat) -> UIFont {
return .systemFont(ofSize: size, weight: .medium)
}
}This might not seem much, or maybe I’m just lazy, but I find it easier to write and read
let nameLabel = UILabel()
nameLabel.font = .regular(15)than
let nameLabel = UILabel()
nameLabel.font = .systemFont(ofSize: size, weight: .regular)