iOS Tips: Exploring Font Lists

Lee young-jun
2 min readDec 22, 2023

--

ShowNote offers a feature to add text objects, allowing users to customize the font style.

You might be interested in making your label or text font editable.

How can we create a component to control the font of the text?

Font Family

To access fonts, we first need to obtain font families.

let fontFamilyNames = UIFont.familyNames

If you print them, they will be displayed as follows:

“Academy Engraved LET”
“Al Nile”
“American Typewriter”
“Apple Color Emoji”
“Apple SD Gothic Neo”

Font Name

When extracting font names from families, you will see many more individual font names than the font families themselves.

let fontNames = UIFont.familyNames

For example, from the AppleSDGothicNeo family, we can obtain seven font names:

“AppleSDGothicNeo-Regular”
“AppleSDGothicNeo-Thin”
“AppleSDGothicNeo-UltraLight”
“AppleSDGothicNeo-Light”
“AppleSDGothicNeo-Medium”
“AppleSDGothicNeo-SemiBold”
“AppleSDGothicNeo-Bold”

You can also view these fonts in the Font Manager. Some families have many fonts.

Font

Using these font names, we can obtain a UIFont to apply to components.

UIFont(name: 'font name', size: 'font size') 

SwiftUI

If you are using UIKit, it is straightforward to apply a font to a label.

label.font = UIFont(name: fontName, size: 10)

Else if you are using SwiftUI, you cannot directly use UIFont. Instead, you should create a Font with UIFont. Fortunately, it’s not difficult.

Text("\(font.fontName)")
.font(.init(font))

But we can’t obtain any information from Font.

But we can’t obtain any information from Font. Therefore, we have to define state with UIFont, not Font.

@State var fonts: [UIFont] = []

Resizing

If you want a larger or smaller font, use withSize. It will return a new font modified with the new font size.

font.withSize(newFontSize)

The full source is in this example repository.

If you found this post helpful, please give it a round of applause 👏. Explore more iOS-related content in my other posts.

For additional insights and updates, check out my LinkedIn profile. Thank you for your support!

--

--

No responses yet