Post

Replies

Boosts

Views

Activity

SwifUI - Set frame on Group of Buttons not working as expected
I want two equally sized buttons. I thought to be efficient using the Group type to set the minWidth and maxWidth on both the buttons, like so: HStack(spacing: 0) { Group { Button { } label: { Text("One") .padding() } .background(.black) .tint(.white) Button { } label: { Text("Two") .padding() } .background(.white) .tint(.black) } .frame(minWidth: 0, maxWidth: .infinity) // <- } .background(.orange) But this doesn't work. The buttons stay their intrinsic content size. To make them take up half of the space, I have to set the .frame on the buttons individually, like so: Button { } label: { Text("One") .padding() } .frame(minWidth: 0, maxWidth: .infinity) // <- .background(.black) .tint(.white) Am I missing some limitations of the Group Type? I thought it would apply .frame() to both? It certainly does something, because adding it to one Button AND the Group, gives desired behavior for that one Button already.
1
0
515
Sep ’23