Text in SwiftUI: size, color, alignment

How to add a text with SwiftUI, set the text color, the text size, and align the text properly, we will answer to these questions in this tutorial. SwiftUI lets you customize Text by applying the .font(), fontWeight(), or the foregroundColor modifier. The default iOS font is called San Francisco and if you don’t explicitly change it, then all of your text will have the default iOS look.

SwiftUI add text

Here is the simple, one line code, to add a text with swiftui.

Text("your text here")

foregroundColor allows you to change the font color

background allows you to put the view backgrond color

You can also change the foreground color of the text as well as the background:

Text("your text here")
    .padding()    
    .background(Color.red)
    .foregroundColor(.white)
    .font(.system(size: 15.0))

Change default system font size, weight and design at the same time:

Text("your text here").font(.system(size: 45, weight: .bold, design: .default))

//you can also set the bold or italic with
Text("your text here")
.bold()
.italic()

Other articles