swift写一个登陆界面
时间: 2024-05-05 22:16:37 浏览: 25
这是一个简单的登陆界面,使用Swift编写:
```swift
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var usernameTextField: UITextField!
@IBOutlet weak var passwordTextField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
@IBAction func loginButtonPressed(_ sender: UIButton) {
guard let username = usernameTextField.text, let password = passwordTextField.text else {
return
}
if username == "admin" && password == "password" {
// 登陆成功,跳转到下一个页面
let nextVC = storyboard?.instantiateViewController(withIdentifier: "NextViewController") as! NextViewController
navigationController?.pushViewController(nextVC, animated: true)
} else {
// 登陆失败,弹出提示框
let alertController = UIAlertController(title: "登陆失败", message: "用户名或密码错误", preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "确定", style: .cancel, handler: nil))
present(alertController, animated: true, completion: nil)
}
}
}
```
这个登陆界面有两个输入框,分别用于输入用户名和密码。用户点击"登录"按钮后,会根据输入的用户名和密码进行验证。如果用户名和密码正确,就跳转到下一个页面;否则就弹出一个提示框,告诉用户登陆失败。
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)