SwiftUI 文本被意外截断

SwiftUI Text being truncated unexpectedly

我有一个包含三个元素的 HStack,例如:

HStack(alignment: .firstTextBaseline) {
    Text(title.uppercased())
        .lineLimit(1)
    Rectangle()
        .frame(height: 1)
        .foregroundColor(Color(.tertiaryLabel))
    Text(value)
        .lineLimit(1)
}

第一个文本元素被截断以支持矩形,这对我来说似乎很奇怪,因为矩形似乎应该根据需要进行压缩以容纳周围的文本。

我发现将 .fixedSize() 添加到我的文本对象可以解决此问题,但这是 best/proper 解决方案吗?

我假设你在寻找 layoutPriority 修饰符,比如

HStack(alignment: .firstTextBaseline) {
    Text(title.uppercased())
        .lineLimit(1)
        .layoutPriority(1)        // << here !!
    Rectangle()
        .frame(height: 1)
        .foregroundColor(Color(.tertiaryLabel))
    Text(value)
        .lineLimit(1)
}