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("=========获得密码")

            }

      

        }

  • 相关阅读:
    Redis底层探秘(二):链表和跳跃表
    Redis底层探秘(一):简单动态字符串(SDS)
    C#进阶之路(六):表达式进行类的赋值
    C#异步编程(五)异步的同步构造
    C#异步编程(四)混合模式线程同步
    C#异步编程(三)内核模式线程同步
    Redis五种数据类型
    C#异步编程(二)用户模式线程同步
    前端面试题整理—jQuery篇
    前端面试题整理—JavaScript篇(一)
  • 原文地址:https://www.cnblogs.com/lcl15/p/6180854.html
Copyright © 2011-2022 走看看