gpt4 book ai didi

ios - 在 SwiftUI 中填写父项

转载 作者:行者123 更新时间:2023-11-28 07:19:47 26 4
gpt4 key购买 nike

我有一个带有 2 个 TextHStack 并且我需要每个 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)
}
}

结果: enter image description here

期望的结果: enter image description here

最佳答案

尝试应用相等的 .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)
}

enter image description here

关于ios - 在 SwiftUI 中填写父项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58537037/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com