Questions tagged [vstack]

A Swift UI view that arranges its children in a vertical line.

193 questions
64
votes
4 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…
tosi
  • 787
  • 1
  • 7
  • 12
61
votes
4 answers

How to adjust spacing between HStack elements in SwiftUI?

I have added spacer(minLength: 5) but it takes the minLength. How 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 { …
Let's_Create
  • 2,963
  • 3
  • 14
  • 33
38
votes
4 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…
Bathan
  • 435
  • 4
  • 9
25
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 { …
Hekes Pekes
  • 1,175
  • 2
  • 12
  • 28
19
votes
3 answers

SwiftUI: Spacer doesn't work at ScrollView

How can I get space in VStack to pin the button at the bottom? ScrollView { VStack() { Text("Title_1") .padding(.bottom, 35.0) Text("Title_2") .padding(.bottom, 32.0) …
Maxim
  • 201
  • 2
  • 5
15
votes
3 answers

SwiftUI Zstack – Make element ignore safe area and another one don't

I have a Zstack like this: ZStack { Image("beach") .resizable() .edgesIgnoringSafeArea(.all) .scaledToFill() VStack { // with a lot of stuff } } I want the image to ignore the safe area, but the Vstack must respect the safe…
Duck
  • 34,902
  • 47
  • 248
  • 470
14
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…
yantronica
  • 353
  • 1
  • 3
  • 12
13
votes
2 answers

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,…
fuzzygoat
  • 26,573
  • 48
  • 165
  • 294
11
votes
2 answers

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…
Frakcool
  • 10,915
  • 9
  • 50
  • 89
11
votes
3 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…
Mark
  • 6,647
  • 1
  • 45
  • 88
10
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…
jo.On
  • 666
  • 1
  • 9
  • 13
10
votes
3 answers

How to set background color on stacks in SwiftUI

I'm trying to utilize the light & dark mode in SwiftUI, but I am struggling to get an elevated color that fits for both light and dark mode. Such as the SystemGray(0-6) colors that Apple showcased. I have attempted to use…
Layne Trout
  • 105
  • 1
  • 1
  • 8
6
votes
1 answer

VStack content is centered instead of aligned left

I would like to left-align the content of a VStack instead of centering it, but I don't know how to do it. Here is my code: struct SortRow: View { var sortType: SortType @AppStorage(sortKey) var currentSorting: SortType = .winOrLoss …
Kelton
  • 151
  • 1
  • 7
6
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:…
Jack
  • 304
  • 6
  • 19
6
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…
Mario Burga
  • 1,107
  • 1
  • 13
  • 19
1
2 3
12 13