我有这个视图可以在多行上显示文本标签,这些标签是我从SwiftUI HStack with Wrap 获得的,但是当我将它添加到 VStack 中时,标签会与我放在下面的任何其他视图重叠。标签显示正确,但视图本身的高度不在 VStack 内计算。如何使此视图使用内容的高度?
import SwiftUI
struct TestWrappedLayout: View {
@State var platforms = ["Ninetendo", "XBox", "PlayStation", "PlayStation 2", "PlayStation 3", "PlayStation 4"]
var body: some View {
GeometryReader { geometry in
self.generateContent(in: geometry)
}
}
private func generateContent(in g: GeometryProxy) -> some View {
var width = CGFloat.zero
var height = CGFloat.zero
return ZStack(alignment: .topLeading) {
ForEach(self.platforms, id: \.self) { platform in
self.item(for: platform)
.padding([.horizontal, .vertical], 4)
.alignmentGuide(.leading, computeValue: { d in …Run Code Online (Sandbox Code Playgroud) 我已经使用adaptive并flexible有minimum没有运气的大小。
struct ContentView: View {
let rows = [
GridItem(.adaptive(minimum: 80)) // lowering this cuases an unwanted shrink of text.
]
var body: some View {
LazyVGrid(columns: rows, spacing: 8) {
ForEach((0...10), id: \.self) { item in
Text("\(Int.random(in: 0...50000))")
.background(Color.yellow)
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
如您所见,似乎它以minimum大小为单位fixed!另外,请注意,我不知道最小尺寸,因为它Text是自行调整尺寸的。
我们如何为LazyVGridor提供自定尺码的项目LazyHGrid?
我希望它看起来像一个标签视图。