Introduction
Text views show words on the screen. Modifiers change how the text looks or behaves.
Text views show words on the screen. Modifiers change how the text looks or behaves.
Text("Your text here")
.modifier1()
.modifier2()Use Text to create a text view.
Chain modifiers after Text to change its style or layout.
Text("Hello, world!")Text("Welcome")
.font(.title)
.foregroundColor(.blue)Text("SwiftUI")
.bold()
.italic()Text("Padded Text")
.padding()
.background(Color.yellow)This app shows three text views stacked vertically. Each text uses different modifiers to change font, color, style, and background.
import SwiftUI struct ContentView: View { var body: some View { VStack(spacing: 20) { Text("Hello, SwiftUI!") .font(.largeTitle) .foregroundColor(.purple) Text("This is a simple text view.") .font(.body) .italic() Text("Styled Text") .bold() .padding() .background(Color.green.opacity(0.3)) .cornerRadius(8) } .padding() } } @main struct MyApp: App { var body: some Scene { WindowGroup { ContentView() } } }
Modifiers do not change the original text but create a new styled view.
Order of modifiers can affect the final look.
Use .padding() to add space around text for better touch targets.
Text shows words on screen.
Modifiers like .font(), .foregroundColor(), and .padding() change text style and layout.
Chain modifiers to combine effects.
Text view do in SwiftUI?Text view is designed to show words or sentences on the screen in SwiftUI.Text view to 24 points?.font(.system(size: value)).Text("Welcome")
.foregroundColor(.red)
.foregroundColor(.blue).foregroundColor overrides previous ones..blue, so the text color will be blue.Text("Hello")
.font(.title)
.padding(10, 20).padding() modifier accepts either no arguments, one argument for uniform padding, or a specific edge set with length..padding(10, 20) is invalid syntax in SwiftUI.Text view that shows "SwiftUI Rocks!" in large bold font, colored green, with padding around it. Which code snippet achieves this correctly?.font(.largeTitle.bold()) chains the bold style properly with the font size..foregroundColor(.green) sets the text color, and .padding() adds default padding around the text..bold() separately which is invalid on Font. Text("SwiftUI Rocks!")
.font(.largeTitle)
.foregroundColor(.green.bold())
.padding() tries to bold the color, which is incorrect. Text("SwiftUI Rocks!")
.font(.bold.largeTitle)
.foregroundColor(.green)
.padding() uses invalid font syntax.Pass the test and this pattern moves unknown