swift输出一个登陆界面app代码
时间: 2024-05-09 11:19:20 浏览: 10
下面是一个简单的登陆界面的 Swift 代码:
```
import UIKit
class LoginViewController: UIViewController {
@IBOutlet weak var usernameTextField: UITextField!
@IBOutlet weak var passwordTextField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func loginButtonTapped(_ sender: UIButton) {
guard let username = usernameTextField.text, let password = passwordTextField.text else {
return
}
if username == "admin" && password == "admin" {
// 登陆成功
let alertController = UIAlertController(title: "登陆成功", message: nil, preferredStyle: .alert)
let okAction = UIAlertAction(title: "确定", style: .default, handler: nil)
alertController.addAction(okAction)
present(alertController, animated: true, completion: nil)
} else {
// 登陆失败
let alertController = UIAlertController(title: "登陆失败", message: "请输入正确的用户名和密码", preferredStyle: .alert)
let okAction = UIAlertAction(title: "确定", style: .default, handler: nil)
alertController.addAction(okAction)
present(alertController, animated: true, completion: nil)
}
}
}
```
这是一个简单的登陆界面,有两个文本框和一个登陆按钮。当用户点击登陆按钮时,程序会检查用户名和密码是否正确,如果正确就弹出一个提示框显示登陆成功,否则弹出一个提示框显示登陆失败。