---
title: "Easier UIFont usage"
slug: easier-uifont-usage
section: tech
date: 2018-11-01T04:37:00.000Z
canonical: https://roland.leth.ro/blog/tech/easier-uifont-usage
---

In a [previous post][1] 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):

```swift
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

```swift
let nameLabel = UILabel()
nameLabel.font = .regular(15)
```

than

```swift
let nameLabel = UILabel()
nameLabel.font = .systemFont(ofSize: size, weight: .regular)
```

[1]:	/improving-uifont-workflow "Improving UIFont workflow"