我想知道为什么在SwiftUI中的两个元素之间会出现这种间距?如何控制/修改它?
我尝试给ExtractedView添加一些padding,但是没有改变任何东西。似乎这是由.frame(height: 56)引起的,但这恰好是按钮的高度,所以不应该导致任何间距。
代码:
![](https://istack.dev59.com/kWdpn.webp)
import SwiftUI
struct FirstLaunchView: View {
var body: some View {
VStack {
ZStack {
Image("first-launch")
.resizable()
.scaledToFill()
.frame(height: 483)
Text("AppName")
.font(.custom("Lobster", size: 24))
.fontWeight(.bold)
.foregroundColor(.white)
.frame(height: 483, alignment: .top)
.offset(x: 0, y: 61)
}
ZStack {
VStack {
ExtractedView(title: "Start", textColor: Color.secondaryColor, bgColor: Color.primaryColor)
ExtractedView(title: "Log in", textColor: Color.primaryColor, bgColor: Color.secondaryColor)
}
}
Spacer()
}
.ignoresSafeArea()
}
}
struct ExtractedView: View {
var title: String
var textColor: Color
var bgColor: Color
var body: some View {
ZStack {
RoundedRectangle(cornerRadius: 27.5)
.fill(bgColor)
.frame(width: 279, height: 56)
RoundedRectangle(cornerRadius: 27.5)
.strokeBorder(Color.primaryColor, lineWidth: 2)
.frame(width: 279, height: 56)
Text(title)
.font(.custom("NotoSans-Regular", size: 18))
.fontWeight(.bold)
.foregroundColor(textColor)
}
.frame(height: 56)
}
}