我正在尝试Text
在a中制作两个,VStack
以采用父对象的整个宽度(VStack
)。
我完全没有主意。
这就是我所拥有的:
var body: some View {
VStack(alignment: .center, spacing: 0) {
Image("image")
.resizable()
.scaledToFill()
.frame(height: 190)
.clipped()
VStack(alignment: .leading, spacing: 8) {
Text(title)
.font(.title)
.background(Color.red)
.fixedSize(horizontal: false, vertical: true)
Text(subtitle)
.font(.subheadline)
.background(Color.yellow)
.fixedSize(horizontal: false, vertical: true)
}
.frame(minWidth: 0, maxWidth: .infinity)
.background(Color.green)
.padding(.top, 24)
.padding(.horizontal, 24)
Button(buttonTitle) { print("Something") }
.frame(maxWidth: .infinity, minHeight: 56)
.background(Color.red)
.foregroundColor(.white)
.cornerRadius(56/2)
.padding(.top, 32)
.padding(.horizontal, 24)
.padding(.bottom, 20.0)
}.background(Color.blue)
.cornerRadius(38)
.frame(minWidth: 0, maxWidth: UIScreen.main.bounds.size.width - 48)
}
这是它的外观:
我希望红色和黄色标签占据绿色的整个宽度VStack
。
我该如何实现?!
最终结果将是:
Text("title")
.font(.title)
.frame(minWidth: 0, maxWidth: .infinity)
.background(Color.red)
要使其左对齐:
HStack {
Text("title")
.font(.title)
Spacer(minLength: 0)
}
.background(Color.red)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句