我有一個包含三個元素的 HStack,例如:
HStack(alignment: .firstTextBaseline) {
Text(title.uppercased())
.lineLimit(1)
Rectangle()
.frame(height: 1)
.foregroundColor(Color(.tertiaryLabel))
Text(value)
.lineLimit(1)
}
第一個文本元素被截斷以支持矩形,這對我來說似乎很奇怪,因為矩形似乎應該根據需要壓縮以容納周圍的文本。

我發現添加.fixedSize()到我的 Text 物件可以解決這個問題,但這是最好/正確的解決方案嗎?
uj5u.com熱心網友回復:
我假設您正在尋找layoutPriority修飾符,例如
HStack(alignment: .firstTextBaseline) {
Text(title.uppercased())
.lineLimit(1)
.layoutPriority(1) // << here !!
Rectangle()
.frame(height: 1)
.foregroundColor(Color(.tertiaryLabel))
Text(value)
.lineLimit(1)
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/453795.html
上一篇:Linux之export命令
