79274955

Date: 2024-12-12 11:41:27
Score: 1
Natty:
Report link

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()
    }
}
Reasons:
  • Blacklisted phrase (0.5): How can I
  • Blacklisted phrase (0.5): I need
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Low reputation (0.5):
Posted by: ITGuy