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
If you have been using Mac for work and suddenly ...
Native advertising has become an essential part o...
Event operation is a job that all operations prof...
Training course content: When it comes to OKR, yo...
People always eat too much easily, sometimes beca...
On January 31, Muddy Waters Research, a well-know...
Do you buy Phalaenopsis orchids for the Chinese N...
I hope that after reading this article, parents c...
Author: Hao Yun Reviewer: Zhong Kai, Director of ...
The speed of light in a vacuum can be said to be ...
Everything needs a plan, and APP operation and pr...
As an App promotion operator , event promotion is...
B2B brand marketing , especially in China, has al...
The bidding hosting industry can make promotion p...
[[197644]] Preface For most junior students, this...