I have a label in my view that I want to use the system font size in medium, with a size of 21 points.
I created a custom extension to re-use the font created:
extension Font { static var primaryButton: Font { return Font.custom("SFUIDisplay-Light", size: 21) } }
However, this does not have any effect. I changed the string to HelveticaNeue-UltraLight
and it did work, so I'm guessing that SFUIDisplay-Light
is simply the incorrect font name.
In font book, it says SFProText-Light
, but that also did not work for me.
What is the correct font name of the San Francisco font in SwiftUI?
Or: how can I set the font size using the system font?
Hold the command key and click the text to bring up a pop-over menu. Choose Show SwiftUI Inspector and then you can edit the text/font properties.
To use a custom font, add the font file that contains your licensed font to your app, and then apply the font to a text view or set it as a default font within a container view. SwiftUI's adaptive text display scales the font automtically using Dynamic Type.
SwiftUI comes with support for all of Dynamic Type's font sizes, all set using the . font() modifier. However, if you ask for a specific font and size, you'll find your text no longer scales up or down automatically according to the user's Dynamic Type settings – it remains fixed.
You can set an explicit size for the system font with:
.font(.system(size: 60))
You can set custom font size like this,
.font(.custom("FONT_NAME", size: 20))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With