在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
//Swift 提醒框 let alert = UIAlertController(title:"提示", message:"用户名或密码错误", preferredStyle: .alert) let cancel = UIAlertAction(title: "取消", style: .cancel, handler: { (action) in print("-------222222222222") }) let ok = UIAlertAction(title: "确定", style: .default, handler: { (action) in print("-----------11111111") }) alert.addAction(cancel) alert.addAction(ok) self.present(alert, animated: true, completion: nil)
//登录界面的View视图 import UIKit
class LoginView: UIView {
var nameTextfiled :UITextField! var passworkTextfiled :UITextField! var loginButton:UIButton! var register : UIButton!
override init(frame : CGRect) { super.init(frame: frame)
self.backgroundColor = UIColor .red creatNameTextfiled() creatPassworkTextfiled() creatLoginBtn() creatRegisterBtn()
}
required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } func creatNameTextfiled() {
nameTextfiled = UITextField() nameTextfiled.placeholder = "输入用户名" nameTextfiled.frame = CGRect(x: 20, y: 200, width: 335, height: 40) nameTextfiled.backgroundColor = UIColor.gray self.addSubview(nameTextfiled) } func creatPassworkTextfiled() {
passworkTextfiled = UITextField() passworkTextfiled.placeholder = "输入密码" passworkTextfiled.frame = CGRect(x: 20, y: 260, width: 335, height: 40) passworkTextfiled.backgroundColor = UIColor.gray self.addSubview(passworkTextfiled) } func creatLoginBtn() {
loginButton = UIButton() loginButton.frame = CGRect(x: 20, y: 320, width: 100, height: 30) loginButton.setTitle("登录", for: .normal) loginButton.backgroundColor = UIColor.gray self.addSubview(loginButton) } func creatRegisterBtn() {
register = UIButton() register.frame = CGRect(x: 255, y: 320, width: 100, height: 30) register.setTitle("注册", for: .normal) register.backgroundColor = UIColor.gray self.addSubview(register) } }
//登录的Controller控制器 import UIKit
class LoginViewController: UIViewController ,UITextFieldDelegate {
var codeV = LoginView() override func viewDidLoad() { super.viewDidLoad() self.view.backgroundColor = UIColor.white codeV = LoginView(frame: CGRect( x:0,y:0,width:375,height:667)) codeV.nameTextfiled.delegate = self codeV.passworkTextfiled.delegate = self codeV.loginButton.addTarget(self, action: #selector(LoginViewController.loginEvent), for: .touchUpInside) codeV.register.addTarget(self, action: #selector(LoginViewController.registerEvent(textFd:)), for: .touchUpInside) self.view.addSubview(codeV) } func loginEvent () {
print("==========")
} func registerEvent(textFd :UITextField ) { print("------------") let reginserVc = RegisterViewController() self.navigationController?.pushViewController(reginserVc, animated:true) } //编辑结束时调用的方法 func textFieldDidEndEditing(_ textField: UITextField) {
if textField.placeholder == "输入用户名" { print("=========获得用户名") }else{ print("=========获得密码") }
} |
请发表评论