A Swift UI view that arranges its children in a vertical line.
Questions tagged [vstack]
193 questions
5
votes
1 answer
Dynamically add elements to VStack in SwiftUI
(Swift 5, SwiftUI)
If I have the following code for a VStack:
struct ContentView: View {
var body: some View {
ScrollView {
VStack(alignment: .leading) {
//Inside of VStack
}.padding()
…

aryanm
- 1,183
- 14
- 26
4
votes
2 answers
Why is LazyHGrid not as high as its items?
I've got a LazyHGrid that shows multiple Text views in one row. That LazyHGrid is inside a VStack. However, the LazyHGrid is higher than it needs to be. What causes the extra space?
struct ContentView: View {
let rows = [GridItem()]
var…

WalterBeiter
- 2,021
- 3
- 23
- 48
4
votes
2 answers
VStack children to fill (not expand) its parent
i am trying to to make the button of an alert view fit the parent VStack. But I can only see two options:
button width as is, no frame modifier. that is not ideal as the button is not wide enough
set the frame modifier to .frame(maxWidth:…

warly
- 1,458
- 1
- 16
- 21
3
votes
1 answer
VSTACK google sheets function doesn't work
Suddently, the Google Sheets functions VSTACK and HSTACK don't work any more.
Any Idea why? I'm in Colombia right know and the google account that I use is in Spanish. But I used to use those functions, even they have google documentation.
The…

Student-22141
- 31
- 1
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…

Andrew Madsen
- 21,309
- 5
- 56
- 97
3
votes
1 answer
SwiftUI: How to know correct order of modifiers?
I'm pretty new to SwiftUI, learning it for the first time, and couldn’t understand why the below snippet doesn’t work. Ideally, the VStack should stretch in all directions and the Image should have a width of 200px without losing its aspect…

Vinay Sharma
- 3,291
- 4
- 30
- 66
3
votes
1 answer
Why LazyHStack takes full height but HStack does not in SwiftUI?
Why does a LazyHStack behaves differently than an HStack regarding the height? (same for the VStack).
import SwiftUI
struct LazyTestView: View {
var body: some View {
LazyHStack {
ForEach(1...10, id: \.self) { int in
…

alpennec
- 1,864
- 3
- 18
- 25
3
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…

RanLearns
- 4,086
- 5
- 44
- 81
3
votes
1 answer
VStack Lower Than Expected SwiftUI
Even though in preview VStack looks promising when I run the app on the simulator or on the phone it appears lower than expected. You can see there is a big gap at the leading of the view from comparing the two images. I have also added layer's…

Mert Köksal
- 817
- 1
- 7
- 26
3
votes
4 answers
Center Item Inside Horizontal Stack
If I have 3 items inside a Horizontal Stack, I thought I could do something like this:
HStack{
Text("test")
Spacer()
item2()
Spacer()
Text("test")
}
to center item2() in between the two Text views. However, the…

Evan
- 1,892
- 2
- 19
- 40
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
…

bain
- 335
- 1
- 6
- 17
3
votes
1 answer
Using swiftUI how can i add datePicker only while textField is in editing mode?
I have added datePicker for now inside HStack. I want to show datePicker only when textField is in editing mode.
struct EditProfile: View {
@Binding var profile: Profile
var body: some View {
List {
HStack {
…

PinkeshGjr
- 8,460
- 5
- 41
- 56
2
votes
1 answer
Dynamically change order of SwiftUI's VStack
How can the order of a VStack be changed during runtime? For HStack, the layout direction can be changed from .leftToRight and .rightToLeft. With ZStack, a zIndex can be adjusted to change order of the views, front to back. Is there something that…

The Bug Slayer
- 43
- 4
2
votes
0 answers
SwiftUI grid layout using Stack
What I am trying to achieve
Making this grid layout using Stack in SwiftUI
How I've currently achieved (with Xcode 14.0.1 (14A400))
import SwiftUI
struct ForStackOverflow: View {
let spacerSize: CGFloat = 1
var body: some View…

Ryo
- 21
- 3
2
votes
1 answer
How to fill VStack in bottom to top approach in SwiftUI?
I would like to add subviews to my VStack from bottom to top manner. By default VStack fills from Center only. I tried by giving Y Offset to subview but that doesn't generate output as expected.
Please find my code sample as below:
import…

HarshIT
- 4,583
- 2
- 30
- 60