我有一个带两个Text
的HStack
,我需要每个Text
都适应它兄弟的身高,我试过.scaledToFill()
,但它不工作
struct ContentView: View {
var body: some View {
return HStack {
Text("test test test test test test test test test test test test test test test test test test test test ")
.background(Color.red)
Text("test test test test test")
.scaledToFill()
.background(Color.red)
}.background(Color.blue)
}
}
结果是:
想要的结果:
发布于 2019-10-24 08:31:26
尝试应用相等的.frame()修饰符
var body: some View {
HStack {
Text("test test test test test test test test test test test test test test test test test test test test ")
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity)
.background(Color.red)
Text("test test test test test")
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity)
.background(Color.red)
}.background(Color.blue)
}
https://stackoverflow.com/questions/58537037
复制相似问题