A Swift UI view that arranges its children in a vertical line.
Questions tagged [vstack]
103 questions
32
votes
3 answers
SwiftUI: How to remove margin between views in VStack?
Using SwiftUI, I created a VStack, which contains some fixed elements and a list element. The reason is, that the user should only scroll the area under the fixed elements. Now I see a space between the second fixed element and the list. I don't…
![](../../users/profiles/5664548.webp)
tosi
- 447
- 1
- 5
- 12
31
votes
2 answers
How to adjust spacing between HStack elements in swiftUI?
I have added spacer(minLength: 5) but it takes the minlenght can I specify the spacing between the text.
I have attached a screenshot for reference I want to reduce the spacing between inner hstack.
HStack…
![](../../users/profiles/10151808.webp)
Let's_Create
- 1,573
- 2
- 8
- 27
19
votes
3 answers
Are there maximum limits to VStack?
I started with a clean project and added 5 buttons and 5 spacers in a VStack and all is good. When I add the 6th spacer at the bottom, the code suddenly won't compile with the error: "Ambiguous reference to member 'buildBlock()'".
What is causing…
![](../../users/profiles/12158242.webp)
Bathan
- 235
- 2
- 9
16
votes
5 answers
VStack inside ScrollView bottom alignment in SwiftUI
Currently building a chat application and I need new messages to appear at the bottom of the screen. I also need to have messages aligned to the bottom. However, using VStack inside ScrollView features top alignment by default.
ScrollView {
…
![](../../users/profiles/9712407.webp)
Hekes Pekes
- 703
- 6
- 17
10
votes
2 answers
SwiftUI: How to have HStack wrap children along multiple lines (like a collection view)?
I'm trying to recreate basic collection view behavior with SwiftUI:
I have a number of views (e.g. photos) that are shown next to each other horizontally. When there is not enough space to show all photos on the same line, the remaining photos…
![](../../users/profiles/901334.webp)
Mark
- 5,965
- 1
- 37
- 77
5
votes
1 answer
SwiftUI position text bottom right?
Is there a better way of positioning text in SwiftUI, in the example below I am positioning the text in the bottom right corner of a ZStack, it works fine but seems long winded, am I missing a simpler way ... The orange lines are just for debugging,…
![](../../users/profiles/164216.webp)
fuzzygoat
- 25,797
- 45
- 159
- 288
5
votes
1 answer
Resize image to screen width using `Vstack` while maintaining aspect ratio
I am working with VStack to show an image (they will be several with different sizes from a json)
I need to show it to occupy the screen width (the width of the vstack and maintaining aspect ratio) and to be properly resized, respecting the height…
![](../../users/profiles/6096415.webp)
Mario Burga
- 997
- 10
- 15
4
votes
1 answer
SwiftUI How to vertically center a view inside a VStack
I would like to have one view in the vertical center of the screen, one view at the top of the screen and one view vertically centered between these two views like so:
This took me 5min to do on a storyboard but I don't seem to find a way to do it…
![](../../users/profiles/3165453.webp)
jo.On
- 508
- 6
- 9
3
votes
1 answer
Match UIStackView's .fill alignment with SwiftUI VStack
I've got a VStack with 3 Texts in it. Each has a different length string. I'd like the VStack's width to be just big enough to fit the widest Text, but I'd also like all three Texts to fill the VStack horizontally.
By default, with this…
![](../../users/profiles/344733.webp)
Andrew Madsen
- 20,769
- 5
- 52
- 92
3
votes
1 answer
SwiftUI VStack align right single element
I'm new at SwiftUI, I'm trying this time to align right a single element (an image) to the right and then the rest of the content should be center aligned.
Just like what happens when you use Spacer() on an HStack but to the other side.
I read about…
![](../../users/profiles/2180785.webp)
Frakcool
- 10,088
- 9
- 41
- 71
3
votes
2 answers
SwiftUI VStack Alignment Bug?
I've been building an application in SwiftUI recently and today I'm noticing that the VStack Alignment is having some strange behavior. No matter the alignment I use, the view isn't aligning outside of the center. See below:
VStack(alignment:…
![](../../users/profiles/3390338.webp)
Jack
- 244
- 5
- 17
3
votes
2 answers
Swift UI setting making rectangle square
In SwiftUI, I have a VStack with a Rectangle inside. The rectangle automatically fills the parent VStack, which is great for the width, but I want to make the height equal to the width so it's square. How do I set the aspect ratio to 1:1 or set…
![](../../users/profiles/4577719.webp)
yantronica
- 113
- 2
- 10
3
votes
2 answers
SwiftUI, ScrollView pushing VStack images up in ZStack
When I apply the scrollview it pushes my whole view up and leaves a white space below the bottom of the ZStack. Not sure why but if someone can please help.
var body: some View {
ZStack{
GeometryReader { geometry in
…
![](../../users/profiles/12272905.webp)
bain
- 223
- 3
- 14
2
votes
2 answers
Move TextField up when the keyboard has appeared in horizontal ScrollView that is inside vertical ScrollView SwiftUI
There has been a question to something related a while ago:
Move TextField up when the keyboard has appeared in SwiftUI
It seems like the previous problem has been fixed. However, if we put the VStack in a ScrollView. SwiftUI seems to ignore the the…
![](../../users/profiles/6575716.webp)
NilsBerni
- 295
- 2
- 11
2
votes
1 answer
SwiftUI: height and spacing of Views in GeometryReader within a ScrollView
ScrollView {
VStack() {
ForEach(0 ..< 5) { item in
Text("Hello There")
.font(.largeTitle)
}
}
}
The above code results in this:
When we add a GeometryReader, the views lose their sizing and…
![](../../users/profiles/428981.webp)
RanLearns
- 3,731
- 3
- 39
- 69