[英]Gap in HStack between two views in SwiftUI
I am trying to have two views in an HStack using SwiftUI.我正在尝试使用 SwiftUI 在 HStack 中有两个视图。 However, I keep getting a gap between the two views.但是,我一直在这两种观点之间存在差距。 The problem occurs in both portrait and landscape layouts.该问题出现在纵向和横向布局中。
my code:我的代码:
struct ContentView: View {
var body: some View {
GeometryReader { g in
HStack {
GeometryReader { g in
HStack {
VStack {
Text("View One")
}
.frame(width: g.size.width * 0.5, height: g.size.height, alignment: .center)
.background(Color.blue)
VStack {
Text("View Two")
}
.frame(width: g.size.width * 0.5, height: g.size.height, alignment: .center)
.background(Color.red)
}
}
}
}
}
}
The spacing can be setup at the time of initialising可以在初始化时设置间距
HStack(spacing: 0) {
//Your code here
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.