SwiftUI — Text View

Ronak Patel
2 min readMay 2, 2023

--

Text: A view that displays one or more lines of read-only text.

Here we’ll learn some default functions of Text in SwiftUI view.

struct ContentView: View{
var body: some View{

Text("Hello World!!!!!")
.font(.title) //Text style

.font(.system(size: 12, weight: .light, design: .serif)) //Specifies a system font to use, along with the style, weight, and any design parameters you want applied to the text.

.foregroundColor(Color.white) //Set the color of the Text

.background(Color.red) // Set the background color of the Text

}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}

In SwiftUI you can stack up to 10 views in the same Stack (VStack, HStack, ZStack), so you can Embed some Views inside another Stack or inside Group {}.

Below is the example, how we can avoid this error.

To avoid this error we can use,

struct ContentView: View{
var body: some View{

VStack{
Text("Line 1")
Text("Line 2")
Text("Line 3")
Text("Line 4")
Text("Line 5")
Text("Line 6")
Text("Line 7")
Text("Line 8")
Text("Line 9")
Text("Line 10")
}
VStack{
Text("Line 11")
}
}
}

THANK YOU!!!!!!!!!!

--

--