zoukankan      html  css  js  c++  java
  • Swift -Login(MVC 纯代码)

    //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, 335, height: 40)

            nameTextfiled.backgroundColor = UIColor.gray

            self.addSubview(nameTextfiled)

        }

        func creatPassworkTextfiled()  {

            

            passworkTextfiled = UITextField()

            passworkTextfiled.placeholder = "输入密码"

            passworkTextfiled.frame = CGRect(x: 20, y: 260, 335, height: 40)

            passworkTextfiled.backgroundColor = UIColor.gray

            self.addSubview(passworkTextfiled)

        }

        func creatLoginBtn() {

            

            loginButton = UIButton()

            loginButton.frame = CGRect(x: 20, y: 320, 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, 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,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("=========获得密码")

            }

      

        }

  • 相关阅读:
    教你OpenCV3.2.0+VS2017开发环境配置
    使用conda 与pip命令管理Python库
    【Python+OpenCV】Windows+Python3.6.0(Anaconda3)+OpenCV3.2.0安装配置
    GitHub Toturial
    C 语言多线程与锁机制
    翻译 | Placing Search in Context The Concept Revisited
    翻译 | Improving Distributional Similarity with Lessons Learned from Word Embeddings
    Derivative of Softmax Loss Function
    从头推导与实现 BP 网络
    施密特正交化 GramSchmidt
  • 原文地址:https://www.cnblogs.com/lcl15/p/6180854.html
Copyright © 2011-2022 走看看