表单选取器看起来很奇怪SwiftUI

问题描述

我正在尝试为我的应用程序设计一个注册/登录页面,但是当我尝试在表单中放置2个选择器时,该表单会填充其余的VStack,因此看起来很糟糕,如下面的屏幕快照所示。关于如何使它紧凑的想法,以便仅使选择器显示在表单内部而没有任何空白?
SwiftUI视图的代码如下。

Screenshot

import SwiftUI

struct SignUpView: View {
    
    @State private var firstNameTextField = ""
    @State private var lastNameTextField = ""
    @State private var emailTextField = ""
    @State private var passwordTextField = ""
    @State private var phoneNumberTextField = ""
    
    @State private var selectedGenderIndex = 0
    @State private var selectedCountryIndex = 0
    
    @Environment(\.presentationMode) private var presentationMode
    @Binding var isSignedIn: Bool
    
    var body: some View {
        VStack {
            Image("Logo")
                .resizable()
                .frame(width: 120,height: 120)
                .padding(.top,25)
            VStack {
                HStack {
                    TextField("* First name",text: $firstNameTextField)
                        .textFieldStyle(RoundedBorderTextFieldStyle())
                    TextField("* Last name",text: $lastNameTextField)
                        .textFieldStyle(RoundedBorderTextFieldStyle())
                }
                .padding(.top)
                TextField("* Email",text: $emailTextField)
                    .textFieldStyle(RoundedBorderTextFieldStyle())
                SecureField("* Password",text: $passwordTextField)
                    .textFieldStyle(RoundedBorderTextFieldStyle())
                TextField("Mobile number",text: $phoneNumberTextField)
                    .textFieldStyle(RoundedBorderTextFieldStyle())
            }
            if errorIsShown {
                HStack {
                    Text("Please fill out the required fields.")
                        .foregroundColor(.red)
                        .font(Font.system(size: 12))
                        .padding(.bottom,2)
                    Spacer()
                }
            }
            if emailWarningIsShown {
                HStack {
                    Text("Please enter a valid email address.")
                        .foregroundColor(.red)
                        .font(Font.system(size: 12))
                        .padding(.bottom,2)
                    Spacer()
                }
            }
            HStack {
                Text("* required")
                    .font(Font.system(size: 12))
                Spacer()
            }
            Form {
                Picker(selection: $selectedGenderIndex,label: Text("Gender")) {
                    Text("Select").tag(0)
                    Text("Male").tag(1)
                    Text("Female").tag(2)
                }
                Picker(selection: $selectedCountryIndex,label: Text("Country")) {
                    Text("Select").tag(0)
                    Text("Country 1").tag(1)
                    Text("Country 2").tag(2)
                    Text("Country 3").tag(3)
                }
            }
            Spacer()
        }
        .padding([.leading,.trailing],20)
    }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...