19
Oct
2020
Make a View fit entire width of its parent
Reading time: 1 min
Ocassionally you wish to make a View fit entire width of its parent. You can do so by setting both minWidth
and maxWidth
:
Text("Some text")
.frame(minWidth: 0, maxWidth: .infinity)
For a Text
specifically, this is even more useful if you wish to have it, say, leading-aligned in a center-aligned VStack
:
VStack { // default alignment is .center
Text("Some text")
.frame(minWidth: 0, maxWidth: .infinity, alignment: .leading)
}