Creating a great user experience lies in making every interaction feel nature and intended to the user.
In a recent project, to make interactions feel more catered, I needed a UILabel to have it’s text scale to fit its bounds to the best extent that it can.
Usage
The implementation can be extended for any UI element (such as UILabel):
let label = UILabel() label.font = UIFont.preferredFont(forTextStyle: .headline)
iOS Font Sizes
| Style | Font | Size |
|---|---|---|
| .largeTitle | SFUIDisplay | 34.0 |
| .title1 | SFUIDisplay (-Light on iOS <=10) | 28.0 |
| .title2 | SFUIDisplay | 22.0 |
| .title3 | SFUIDisplay | 20.0 |
| .headline | SFUIText-Semibold | 17.0 |
| .callout | SFUIText | 16.0 |
| .subheadline | SFUIText | 15.0 |
| .body | SFUIText | 17.0 |
| .footnote | SFUIText | 13.0 |
| .caption1 | SFUIText | 12.0 |
| .caption2 | SFUIText | 11.0 |