Introduction
In our last article, we have seen How to add Font and FontWeight in SwiftUI. We covered only these two modifiers for Text view. SwiftUI gives us a variety of view modifiers to allow us to modify the appearance and behavior of the text views in our iOS app. These modifiers can be used to change the font, color, alignment, and other properties of text views. In this article, we'll see some of the most commonly used view modifiers for text in SwiftUI.
View Modifiers for Text view
Bold and Italic
If we want to make our text look bold or italic, we can use the bold() or italic() modifiers, respectively:

Text("Hello, World!")
.bold()

Text("Hello, World!")
.italic()
Color
We can also change the color of our text using the foreground color modifier. This modifier takes a color as a parameter. We can simply press the dot in the foreground color, and it will show us some of the colors present in SwiftUI. We can select any of them to make our text colorful.

Text("Hello, World!")
.foregroundColor(.red)

Alignment
The alignment modifier gives us the functionality to change the alignment of our text within its container. We can use the .leading, .center, and .trailing alignment options:

Text("Hello, world!")
.frame(width: 200, height: 50)
.background(Color.yellow)
.alignmentGuide(.leading) { _ in 50 }
Line Spacing and Line Limit
The lineSpacing and lineLimit modifiers allow us to change the spacing between lines and limit the number of lines of text, respectively:








Join the conversation! Your thoughts help the community grow.