Custom fonts in SwiftUI?

Is it possible to use custom fonts in SwiftUI? I can only find the "title", "subheadline", etc. type enumerations. But if I actually want to define a new font that I am importing to the project, how would I go about that?

Accepted Reply

Found this in docs:


.font(Font.custom("name-of-font", size: 20))

Replies

Found this in docs:


.font(Font.custom("name-of-font", size: 20))

Have you got it to actually display your custom font? I'm using the following, but it's not actually displaying the custom font, either in the preview or in the simulator.


                Text("Sample Text Line 1\r\nSample Text Line 2\r\nSample Text Line 3")
                    .font(Font.custom("Montserrat-Bold", size: 60.0))
                    .fontWeight(.heavy)
                    .color(.white)
                    .multilineTextAlignment(.center)
                    .lineLimit(0)


It displays text in the correct size and color, but using the standard font -- not Montserrat-Bold.


I tried adding the custom font files to the Assets.xcassets and just dragging the whole font folder into my project. Neither seems to work.

DOH! I'm such a noob. You still need to mark the font files as "Target Membership" and add them as "Fonts provided by application" in info.plist.