- August 18, 2025
- Mins Read
WrappingHStack is a UI Element that works in a very similar way to HStack, but automatically positions overflowing elements on next lines.
WrappingHStack {
Text(“WrappingHStack”)
.padding()
.font(.title)
.border(Color.black)
Text(“can handle different element types”)
Image(systemName: “scribble”)
.font(.title)
.frame(width: 200, height: 20)
.background(Color.purple)
Text(“and loop”)
.bold()
WrappingHStack(1…20, id:\.self) {
Text(“Item: \($0)”)
.padding(3)
.background(Rectangle().stroke())
}.frame(minWidth: 250)
}
.padding()
.border(Color.black)
Requirements iOS 13+
.package(url: “https://github.com/dkk/WrappingHStack”, .upToNextMajor(from: “2.0.0”))
Simply add the following line to your Podfile
:
pod ‘WrappingHStack’
Import the WrappingHStack package to your view:
import WrappingHStack
use it like you would use HStack for single elements:
WrappingHStack {
/* some views */
NewLine() // Optional: Use NewLine to force the next element to be placed in a next line
/* some more views */
}
or like a ForEach to loop over items:
WrappingHStack(1…30, id:\.self) {
Text(“Item: \($0)”)
}
You control the position of the items by using the parameter alignment
, which sets the HorizontalAlignment
of the items. I.e. leading, trailing or centered.
For even more convenience and flexibility, WrappingHSTack
offers the parameter spacing
, that defines how the spacing will be calculated. It can be one of the following types:
.constant
: for fixed spacing, each line starts with an item and the horizontal separation between any 2 items is the given value..dynamic
: to have the items fill the width of the WrappingHSTack. You can pass a minimal spacing..dynamicIncludingBorders
to fill the full width with equal spacing between items and from the items to the border. You can pass a minimal spacing.Recognize your user's voice elegantly without having to figure out authorization and audio engines. SwiftSpeech Examples Features Installation Getting Started ...
Example To run the example project, clone the repo, and run pod install from the Example directory first. Requirements iOS 14.0 Installation ...
SlidingRuler is a Swift package containing a SwiftUI control that acts like an linear infinite slider or a finite, more precise ...