ios – Align merchandise .trailing with out stretching container in SwiftUI


I’ve a button which is nested in another parts. I need the button to be aligned to the appropriate (trailing), though the remainder of the VStack gadgets are main.

After I use a Spacer() in an HStack, it stretches the HStack, and its mother or father container, to the width of the display screen. I don’t wish to change the width of the mother or father, I simply wish to proper align the button throughout the present sized container.

Replicated under:

var physique: some View {
    VStack(alignment: .main, spacing: 0) {
        Spacer()
        VStack {
            VStack(alignment: .main) {
                Textual content("Lengthy textual content to stretch container a bit")
                    .font(.physique)
                    .padding(.backside)
                Textual content("However not stretch an excessive amount of")
                    .font(.caption2)
                    .opacity(0.8)
                HStack() {
//                       Spacer()
                    Button(motion: {print("Howdy")}) {
                        Textual content( "(Picture(systemName: "chevron.proper"))")
                    }
                    .buttonStyle(.borderedProminent)
                }
            }
            
        }
        .padding()
        .background(Shade.accentColor)
        .cornerRadius(15)
    }
}

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles