Table of Contents
We can convert UIKit
UIFont to SwiftUI
init(_ font: CTFont) initializer.
The initializer accepts
CTFont as an argument. The
CTFont is an opaque type that represents a font object.
UIFont can toll-free bridged to
Here is an example of converting UIKit
UIFont to SwiftUI
let uiFont = UIFont.systemFont(ofSize: 18, weight: .bold)
let font = Font(uiFont)
1 As you can see, we can initialize
Font by passing an
UIFont instance as an argument.
We can easily convert
Font, but not another way round. But this might not be a problem since
UIFont contains much more flexibility and method than
Anything that you can do with
Font, you probably find an equivalent way to do it in
Toll-free bridging means you can use that bridged data type interchangeably as a parameter without any casting https://developer.apple.com/library/archive/documentation/General/Conceptual/CocoaEncyclopedia/Toll-FreeBridgin/Toll-FreeBridgin.html. ↩︎
Read more article about SwiftUI, UIKit, Font, Text, or see all available topic
Enjoy the read?
If you enjoy this article, you can subscribe to the weekly newsletter.
Every Friday, you'll get a quick recap of all articles and tips posted on this site. No strings attached. Unsubscribe anytime.
Feel free to follow me on Twitter and ask your questions related to this post. Thanks for reading and see you next time.
If you enjoy my writing, please check out my Patreon https://www.patreon.com/sarunw and become my supporter. Sharing the article is also greatly appreciated.Become a patron Buy me a coffee Tweet Share
How to make SwiftUI button with buttonStyle expand to full width
SwiftUI got many beautiful built-in button styles. One problem you might get is it isn't obvious how to control the size of it. Let's learn how to do it.
SF Font Expanded, Condensed, and Compressed: Three New font width styles in iOS 16
In iOS 16, Apple introduces three new width styles to the SF font family. Let's see what they look like and how to use them.