是否有可能完全显示蓝色标签(当前被截断)然后自动换行?
NavigationLink(destination: GameListView()) {
VStack(alignment: .leading, spacing: 5){
// Name der Sammlung:
Text(collection.name)
.font(.headline)
// Optional: Für welche Konsolen bzw. Plattformen:
HStack(alignment: .top, spacing: 10){
ForEach(collection.platforms, id: \.self) { platform in
Text(platform)
.padding(.all, 5)
.font(.caption)
.background(Color.blue)
.foregroundColor(Color.white)
.cornerRadius(5)
.lineLimit(1)
}
}
}
.padding(.vertical, 10)
}
Run Code Online (Sandbox Code Playgroud)
此外,蓝色标签中不应有换行符:
这就是它最终的样子:
我有这个视图可以在多行上显示文本标签,这些标签是我从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)