Questions tagged [hstack]

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

This document contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

HStack - SwiftUI | Apple Developer Documentation

153 questions
1
vote
2 answers

Aligning views in 2 different stacks using custom alignment guide in SwiftUI

I have 2 HStacks sitting in one VStack as follows: What I'm trying to achieve is to align the leading of Title 2 and Title 4 with each other. And also Title 1 and Title 3 to each other without using frames. Like the following: Here is my code…
Mina
  • 2,167
  • 2
  • 25
  • 32
1
vote
2 answers

How to size subviews in HStack by percentage without GeometryReader (SwiftUI)?

I've got a simple HStack with subviews inside. How can I tell the first subview to be 60% the size of the HStack without using a GeometryReader? struct ContentView: View { var body: some View { HStack { …
WalterBeiter
  • 2,021
  • 3
  • 23
  • 48
1
vote
2 answers

Center Elements in HStack

I am trying to implement a text field that is centered, but I cannot seem to do so. I tried doing it in 3 different ways, but it is still leading aligned. //Mobile Number Field HStack(alignment: .center) { …
Jacob F
  • 135
  • 3
  • 13
1
vote
1 answer

Make view in scroll view centered in available space between top vstack with labels (it can change)

I have scroll view in which on the top can be different number of texts, from zero to many. And in the center I have another view which should be vertically centered in AVAILABLE SPACE, so if we have no texts on the top - my view should be in the…
1
vote
1 answer

Stacking a HStack below a ZStack in SwiftUI

Disclaimer: New to SwiftUI I know a ZStack() view allows me to overlap views, which is what I want for the heading section of the app. I set the ZStack() to not take up the entire height and had expected an HStack(), placed after the ZStack() to do…
Dan
  • 2,304
  • 6
  • 42
  • 69
1
vote
1 answer

SwiftUI: buttons inside a HStack cause the overall HStack to exceed the bounds

I have a SwiftUI which holds a number of buttons inside of an HStack. These buttons have both an icon and some text, laid out vertically. I am running into the problem where the buttons can become too wide: the HStack is going outside of the bounds…
Kevin Renskers
  • 5,156
  • 4
  • 47
  • 95
1
vote
1 answer

Limit the number of views in a SwiftUI HStack based on a max width

I have a requirement to show tags in a horizontal view. The tags should display only one line, but if there are more tags than will fit in the given width, it should show as many as it can, with a truncation indicator the end. When there is enough…
Jasarien
  • 58,279
  • 31
  • 157
  • 188
1
vote
1 answer

How to show last index as default in Hstack SwiftUI

I write the following code and display data into Hstack on scrollview in my case, I receive 10 items from a service call and shown those in Hstack When the user enters into screen first time first 5 days are visible, But I need to show the last 5…
1
vote
2 answers

How to build scrollable side menu using text rotation (or something similar) in SwiftUI?

I want to build a menu like the image bellow where I can scroll between menus. I did try multiple combinations with HStack/VStack in ScrollView and rotation modifier on Text and/or stacks. However, none of my attempts really works as…
Hans Rietmann
  • 396
  • 5
  • 13
1
vote
2 answers

Add forward and Backward buttons on Hstack in SwiftUI

I write the following code for date picker customization, and get the output as Here I want to add the forward and Backword buttons for the Date picker this way Anyone help me with my code modification to add forward and Backword buttons with…
1
vote
1 answer

Remove spacing between HStacks embedded in Stack

I am trying to stack two HStacks filled with circles, however, no matter what I do, I cannot get rid of the spacing between the two. VStack { VStack(spacing: 0) { HStack { ForEach(viewModel.lights) {…
Thomas Braun
  • 1,109
  • 2
  • 13
  • 27
1
vote
0 answers

SwiftUI - onTapGesture on HStack works, until it stops working

We have a custom view, that we use in forms (its main feature is to be able to show a nice border on if there is a validation error on the form): struct ButtonNavigationLink: View { var label: String var markingType: MarkingType = .none …
memical
  • 2,353
  • 1
  • 24
  • 36
1
vote
2 answers

When there are different sized Text in a HStack, top alignment doesn’t apply to larger sized text

I have a HStack with multiple elements, particularly two Texts with different font sizes. I want both text to be aligned to the top of the view. HStack(alignment: .top) { Image(systemName: "cloud.drizzle.fill") Text("14°") …
Barrrdi
  • 902
  • 13
  • 33
1
vote
1 answer

How align columns for multiple items on a VStack on SwiftUI?

In the sample below, if I have a VStack followed for a HStack, how can I make the width of the HStack follow the same as a grid ? struct VStackAlignmentView: View { let data = ["a", "b", "cdefghl alalala", "i", "j"] var body: some View { …
Pedro Antunes
  • 192
  • 1
  • 6
1
vote
1 answer

Vstack chiled Hstack elements do not distribute equally

I have two Hstack inside Vstack but Elements of Hstack are not distributed equally due to text length. Due to Current task and Completed Task Text length my Hstack do not equally distribute. How can I achieved equally distribution? I have to use…