PrefaceIn iOS 16, Apple introduced three new width style fonts to the SF font library.
UIFont.WidthApple introduced a new structure UIFont.Width, which represents a new width style. There are currently four styles.
SF font and new width stylesHow to use SF fonts with the new width style To use the new width style, Apple has a new UIFont class method that accepts the new UIFont.Width . class UIFont : NSObject { You can use the new method as you normally would when creating fonts. let condensed = UIFont.systemFont(ofSize: 46, weight: .bold, width: .condensed) SwiftUI
Currently (Xcode 16 beta 6), this new width style and initializer is only available in UIKit, but luckily, we can easily use it in SwiftUI. There are many ways to integrate UIKit into SwiftUI. I’ll show you two ways to use the new width styles in SwiftUI.
Convert UIfont to FontWe know from how to convert UIFont to Font in SwiftUI [1] that Font has an initializer method that receives a UIFont as a parameter. The steps are as follows
struct NewFontExample: View {
Creating a Font extensionThis method is actually the same as converting UIfont to Font. We just need to create a new Font extension to make it easier to use in SwiftUI. extension Font { Create a static function to pass the parameters required by UIFont. Then, initialize UIFont and create Font. We can use it like this. Text("Compressed") How to use the new width styleYou can use it anywhere you want. There won't be any restrictions, all new widths will have the same dimensions, same height, only the width will change. Here is the same text, same font size and same font style with different font width styles. New Width Style AdvantagesYou can use new width styles on top of existing font styles, such as thin or bold, to create a unique experience in your app. Apple uses it in their Photos app, in the "Memories" feature, by combining different font widths and styles in the title or subtitle. Here are some font combinations of different widths and styles to inspire you. Text("Pet Friends") You can also use the new width styles to control the readability of text. The following example shows how different width styles affect the number of characters per line and paragraph length: Download this fontYou can download these new font width styles from the Apple Font Platform[2]. After downloading and installing, you will find a new style that combines the existing width styles with the new width styles.
References[1] How to convert UIFont to Font in SwiftUI: https://www.jianshu.com/p/56ee0d1ea0e1. [2] Apple Font Platform: https://developer.apple.com/fonts/. |
<<: Sourcery Swift Package command line plugin
>>: Creating a Line Chart with SwiftUI Charts in iOS 16
The operations director who achieved 10 million ap...
There is no fixed price for the customization of ...
Rice is a common staple food, and many people mak...
As the weather warms up, it's time to wear sh...
Recently, "Nezha 2: The Devil Boy Conquers t...
As people's quality of life continues to impro...
Today is the 15th day of the seventh lunar month,...
Audit expert: Shen Yingjian Director of the Nutri...
Nowadays, “two Weibo and one Douyin” have become ...
In the late 1960s, in order to get rid of the oil...
After Luckin Coffee was suspended and delisted, i...
Recently, Tik Tok has become a battleground for M...
Not long ago, Ms. Wang from Fuzhou, Fujian almost...
Recently, the Tianzhou-3 cargo spacecraft re-ente...
Curiosity and idealism are the driving forces tha...