首页 > 解决方案 > 在 SwiftUI 中添加 Rectangle() 时单元格行自动调整大小损坏

问题描述

我无法Rectangle()在水平堆栈中定位简单。如果我添加它,Text()停止调整大小是这样的:

失败

如果我删除Rectangle(),炒锅罚款:

好的

我尝试更改 frame、relativeSize、layoutPriority 等等,但没有任何效果。我认为这是一个错误,但对于任何类型的几何类型(如 Circle、RoundedRectangle 等)都失败了。另一方面,Image()它工作正常。

有什么建议吗?

谢谢!

标签: iosswiftuixcode11

解决方案


只是从我的脑海中写出来,可能是错误的,但是尝试在 VStack 中添加矩形,这样它就不会将单元格包裹在它周围。

VStack {
    Rectangle()
    Spacer()
}

让我知道它是否有效。

编辑*

必须尝试一下,并找到一个“有点”的解决方案,它可能会引导您正确答案,您只需将矩形放置在右上角。将此作为您的 RowItem。

ZStack {
        Rectangle()
            .foregroundColor(Color.red)
            .frame(width: 10, height: 10)

        Text("Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.")
        .lineLimit(nil)
        .layoutPriority(999)
        .padding(.horizontal, 20)
    }

推荐阅读