I am trying to have two views in an HStack using SwiftUI. 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)
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
The spacing can be setup at the time of initialising
HStack(spacing: 0) {
//Your code here
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
55 次 |
| 最近记录: |