---
title: "Improving UIFont workflow"
slug: improving-uifont-workflow
section: tech
date: 2016-04-14T17:06:00.000Z
canonical: https://roland.leth.ro/blog/tech/improving-uifont-workflow
---

Usually an app has fonts with well defined purposes. So why not let `enums` make our lives easier, a little bit? First, a couple of them, to define our font families and weights:

```swift
struct Font {
  private enum Family: String {
    case avenirNext
    case proximaNova 
  }
  
  private enum Weight: String {
    case regular
    case medium
    case demiBold
    case bold
  }
}
```

Then a method to easily create fonts:

```swift
private static func baseFont(family: Family, size: CGFloat, weight: Weight = .regular, italic: Bool = false) -> UIFont {
  let font = family.rawValue
  let modifier = weight.rawValue + (italic ? "Italic" : "")
  return UIFont(name: "\(font)-\(modifier)", size: size)!
}
```

Finally, the properties:

```swift
static let barButton = Font.baseFont(family: .avenirNext, size: 16, weight: .medium)
static let header    = Font.baseFont(family: .proximaNova, size: 18, weight: .demiBold)
```

If the app has only one font family, everything becomes even simpler, by removing `Family` and the related params.