Create a Text View in SwiftUI
Written by Team Kodeco
In SwiftUI, you can display text on the screen simply by creating an instance of the Text view and providing it with some string content.
Here’s an example of the Text view in action:
struct ContentView: View {
var body: some View {
Text("Hello, World!")
}
}
In the code above, you create a ContentView struct that returns a Text view with the string “Hello, World!”. This view will display that message on the screen when it is rendered.
You can customize the properties of the Text view to change the font, color and other characteristics. For example, you can change the font and size of the text by using the font modifier, like this:
Text("Hello, World!")
.font(.title)
This styles the text to the built-in .title text style, which is larger than the default font size.