下面的代码是创建一个自定义按钮
import SwiftUI
let skyBlue = Color(red: 75/255, green: 170/255, blue: 193/255)
struct RegisterButtonView: View {
var body: some View {
GeometryReader { geo in
HStack {
Spacer()
Text("Register")
.foregroundColor(Color(.white))
.font(.system(size: geo.size.width / 20))
.bold()
Spacer()
}
.frame(width: geo.size.width * 4/9, height: geo.size.height / 7)
.background(skyBlue)
.cornerRadius(60)
}
}
}
struct RegisterButtonView_Previews: PreviewProvider {
static var previews: some View {
RegisterButtonView()
}
}
但是,整个按钮视图包含了 GeometryReader 引入的额外空间,因此当我将此视图放到根视图时,无法消除空间。