Swift 製作Login 介面

在畫面上加入2個text field,分別代表帳號和密碼,從帳號的text field按鍵盤的next跳到下一個text field,從密碼是text field是return,按了return 收下來

帳號的textField把Return Key設成Next

密碼的textField把Return Key設成 Done並且將Secure Text Entry勾起來,就可以隱藏已輸入的密碼

func textFieldShouldReturn(_ textField: UITextField) -> Bool {
if textField == account
{
password.becomeFirstResponder()
}
else
{
if account.text == ac && password.text == pw
{
password.resignFirstResponder()
let controller = self.storyboard?.instantiateViewController(withIdentifier: “wellcome”)
controller?.modalTransitionStyle = .flipHorizontal
self.present(controller!, animated: true, completion: nil)
}
else
{
password.resignFirstResponder()
account.text = “”
password.text = “”
let alertController = UIAlertController(title: “Try Again”, message: “使用者名稱或密碼有誤”, preferredStyle: .alert)
let ok = UIAlertAction(title: “OK”, style: .default, handler: nil)
alertController.addAction(ok)
self.present(alertController, animated: true, completion: nil)
}
}
return true
}
One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.