admin管理员组文章数量:1129450
I'm encountering an issue with inconsistent padding when using a Text view inside a VStack. When the Text is present, the padding becomes uneven, causing the horizontal and vertical padding to be inconsistent. However, when I remove the Text, the padding behaves as expected and remains consistent. I've found a workaround by adding a frame modifier to the Text, but I don't want to apply a frame in my UI design. Is there a way to resolve this issue without using the frame modifier?
struct ContentView: View {
private let spacing: CGFloat = 20.0
@State private var show: Bool = Bool()
var body: some View {
VStack(spacing: spacing) {
if (show) {
Text("Hello, world!")
.background(Color.blue)
}
Color.black
.frame(width: 200.0, height: 200.0)
Button("Reset") {
show.toggle()
}
.buttonStyle(.borderedProminent)
}
.background(Color.red)
.padding(spacing)
}
}
本文标签: swiftInconsistent Padding in VStack with Text ViewStack Overflow
版权声明:本文标题:swift - Inconsistent Padding in VStack with Text View - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736728147a1949842.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论