Skip to content

How to use the spacing property #49

Closed Answered by dkk
CalebKierum asked this question in Q&A
Discussion options

You must be logged in to vote

ForEach should be used when you want it to be handled as a single element. If you want each element of the ForEach to be seen as a different element by WrappingHStack, just exchange the ForEach keyword with WrappingHStack. Like this:

 WrappingHStack(spacing: .constant(20.0)) {
    WrappingHStack(0 ..< 10, id: \.self) { index in
                Button("\(index)") { }
                    .padding()
                    .background(.blue)
                    .foregroundStyle(.white)
                    .clipShape(Capsule())
    }
}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by dkk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants