And then I need to use them to create UIKit's UIFont. How can I get parameters from Font struct?
That is simply not possible. There is (currently) no direct way to create a UIKit UIFont
instance from a SwiftUI Font
or to get the properties of a SwiftUI Font
.
That's why you need to take a different approach. The opposite way is possible, i.e. to create a SwiftUI Font
from a UIFont
instance.
I.e. you could use UIFont
instances as a common base and use them in SwiftUI views:
extension UIFont {
static let customFont = UIFont(name: "CustomFont", size: 15)!
}
extension Font {
static let customFont = Font(UIFont.customFont)
}
struct ContentView: View {
var body: some View {
VStack {
Text("Hello, world!")
.font(.customFont)
}
.padding()
}
}