SwiftUI Codes
Best SwiftUI Code Warehouse

Lesson 2: Basic Views with SwiftUI

Objective:

Learn how to use Text and Image views, style them, and position them within the interface.

Content:

1. Text View

The Text view displays a string of text.

Displaying Text:

Text("Welcome to SwiftUI")

Styling Text:

Text views can be styled with various modifiers:

Example:

Text("Welcome to SwiftUI")
    .font(.largeTitle)
    .foregroundColor(.blue)
    .bold()
    .italic()
    .padding()

Explanation:

2. Image View

The Image view displays an image.

Displaying Images:

Image("exampleImage")

Styling Images:

Image views can be styled with various modifiers:

Example:

Image("exampleImage")
    .resizable()
    .aspectRatio(contentMode: .fit)
    .frame(width: 200, height: 200)
    .clipShape(Circle())

Explanation:

3. Combining Text and Images

Views can be combined to create more complex layouts:

VStack {
    Text("SwiftUI Logo")
        .font(.title)
        .padding()
    Image(systemName: "swift")
        .resizable()
        .aspectRatio(contentMode: .fit)
        .frame(width: 100, height: 100)
        .foregroundColor(.orange)
}

Explanation:

Lesson 3: Layouts and Stacks