我有一个HStack
,其中有2个Text
,我需要每个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)
}
}
答案 0 :(得分:0)
尝试应用相等的.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)
}