---
title: "Changing (just) the font size of a button"
slug: changing-just-the-font-size-of-a-button
section: tech
date: 2015-09-16T22:45:00.000Z
canonical: https://roland.leth.ro/blog/tech/changing-just-the-font-size-of-a-button
---

We have in the app a generic button, styled to look the same across the app -  from shadows to title. Some places require a smaller font though, and I didn't really want to duplicate code, so something had to be done. Here's my little trick for it:

```swift
// titleLabel is nil only for system buttons, as per documentation
button.titleLabel!.font = UIFont(
  name: button.titleLabel!.font.fontName,
  size: button.titleLabel!.font.pointSize - 2
)
```
