我有一個表單,如果用戶沒有向電子郵件和密碼欄位提供足夠的憑據,則會出現提示。問題是提示正在創建它們所在的額外行(在電子郵件和密碼下)。

我嘗試隱藏分隔符,但隨后我留下了巨大的空間差距。有沒有一種方法可以洗掉串列行,并在文本出現時讓每個元素向下移動?密碼提示并不明顯,因為按鈕和行之間仍有空間。

NavigationView{
ZStack{
Form{
Section(){
TextField("FirstName", text: $userInformation.firstname)
TextField("LastName", text: $userInformation.lastname)
TextField("Email", text: $userInformation.email)
Text(userInformation.emailPrompt)
.font(.caption).italic().foregroundColor(.red)
.listStyle(.inset)
SecureField("Passsword", text: $userInformation.password
).autocapitalization(.none)
Text(userInformation.passwordPrompt)
.font(.caption).italic().foregroundColor(.red)
}
.listRowBackground(Color.clear)
.padding()
.navigationBarTitle(Text("Lets Get Started"))
.navigationBarTitleDisplayMode(.automatic)
.font(.system(size:18))
.listStyle(GroupedListStyle())
}
NavigationLink(destination: JournalEntryMain() .navigationBarHidden(true)){
Text("Sign Up")
.frame(width: 250, height: 20)
.foregroundColor(.white)
.padding()
// .multilineTextAlignment(.leading)
.background(LinearGradient(gradient: Gradient(colors: [.orange, .pink]), startPoint: .leading, endPoint: .bottom))
.font(.title3)
.background(.clear)
.cornerRadius(5)
.offset(y:30)
.opacity(userInformation.isSignUpComplete ? 1 : 0.5)
}
class FormViewModel: ObservableObject {
@Published var firstname = ""
@Published var lastname = ""
@Published var email = ""
@Published var gender = ""
@Published var password = ""
func isPasswordValid() -> Bool {
let passwordTest = NSPredicate(format: "SELF MATCHES%@", "^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z]).{8,15}$")
return passwordTest.evaluate(with: password)
}
func isEmailValid() -> Bool {
let emailTest = NSPredicate(format: "SELF MATCHES%@", "^([a-zA-Z0-9_\\-\\.] )@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-] \\.) ))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$")
return emailTest.evaluate(with: email)
}
//email and password prompts if incomplete or incorrect
var emailPrompt: String {
if isEmailValid() || email == "" {
return ""
} else {
return "*Please enter a valid email address"
}
}
var passwordPrompt: String {
if isPasswordValid() || password == ""{
return ""
} else {
return "*Password must be 8-15 letters, with atleast one uppercase and one number"
}
}
var isSignUpComplete: Bool {
if !isPasswordValid() || !isEmailValid() || firstname == "" || lastname == "" {
return false
}
return true
}
}
uj5u.com熱心網友回復:
最簡單的方法是有條件的:
if userInformation.passwordPrompt != "" {
Text(userInformation.passwordPrompt)
.font(.caption).italic().foregroundColor(.red)
}
這將有條件地將其從視圖中洗掉。您還可以為外觀/消失設定影片。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/437162.html
下一篇:使用yup驗證后重定向到下一頁
