一个类似于 HStack 的 SwiftUI 组件,它将水平溢出的子视图包装到下一行
包装鞋钉
类似于 的 SwiftUI 组件将水平溢出的子视图包装到下一行。HStack
概述
该库基于 SwiftUI 的协议,因此具有以下部署要求:Layout
iOS 16.0+, iPadOS 16.0+, macOS 13.0+, Mac Catalyst 16.0+, tvOS 16.0+, watchOS 9.0+
组件的签名:
WrappingHStack(alignment: Alignment = .center,
horizontalSpacing: CGFloat? = nil,
verticalSpacing: CGFloat? = nil)
默认情况下,组件使用对齐方式,但也支持以下对齐方式值:、、。其余的被视为 。.center
.center
.leading
.topLeading
.top
.topTrailing
.trailing
.bottomTrailing
.bottom
.bottomLeading
.center
默认情况下,组件使用系统提供的间距,但也可以指定显式和 .horizontalSpacing
verticalSpacing
The component assumes that the largest subview fits into the bounds and there are no infinitely growing subviews. The component assumes that it can grow vertically as much as necessary to fit into the width constraint.
Examples
An array of tags:
WrappingHStack(alignment: .leading) {
ForEach(tags) {
Text($0.text)
.foregroundColor(Color.white)
.padding(.horizontal, $0.horizontalPadding)
.padding(.vertical, $0.verticalPadding)
.background(Color.gray)
.cornerRadius(16)
}
}
Installation
You can add WrappingHStack to an Xcode project by adding it as a package dependency.
If you want to use WrappingHStack in a SwiftPM project,
it’s as simple as adding it to a clause in your :dependencies
Package.swift
dependencies: [
.package(url: "https://github.com/ksemianov/WrappingHStack", from: "0.1.0")
]
License
This library is released under the MIT license. See LICENSE for details.