kschins
kschins

Reputation: 1224

How do I specify x and/or leading padding for lead alignment text views in SwiftUI?

Given the following code snippet, I can align the leading edges of the text views but how can I specify that I want them to be aligned with their leading edges yet a certain number of pixels from the left edge of the actual VStack container?

VStack {
Text("Simple Swift Guide")
    .font(.title)
Text("SwiftUI Tutorials")
    .font(.subheadline)
    .foregroundColor(.gray)
 }
 .frame(maxWidth: .infinity)
 .background(Color.yellow)

enter image description here

Upvotes: 1

Views: 98

Answers (1)

Asperi
Asperi

Reputation: 258541

Here is possible approach for your snippet (if I understood your goal correctly) - alignment is external so internal VStack content can be any.

demo

    VStack(alignment: .leading) {
        Text("Simple Swift Guide")
            .font(.title)
        Text("SwiftUI Tutorials")
            .font(.subheadline)
            .foregroundColor(.gray)
    }
    .frame(maxWidth: .infinity, alignment: .leading)
    .padding(.leading, 25)
    .background(Color.yellow)

Upvotes: 1

Related Questions