Advertisement
Guest User

login

a guest
Aug 20th, 2018
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.75 KB | None | 0 0
  1. //
  2. //  loginController.swift
  3. //  MyFlags
  4. //
  5. //  Created by Hackeru_Student on 8/15/18.
  6. //  Copyright © 2018 Hackeru_Student. All rights reserved.
  7. //
  8.  
  9. import UIKit
  10.  
  11. class loginController: UIViewController {
  12.  
  13.     @IBOutlet weak var txtUser: UITextField!
  14.     @IBOutlet weak var txtPassword: UITextField!
  15.     override func viewDidLoad() {
  16.         super.viewDidLoad()
  17.        
  18.     }
  19.  
  20.     @IBAction func btnLogin(_ sender: Any) {
  21.         let myUser = txtUser.text!
  22.         let myPass = txtPassword.text!
  23.         if myUser == "zeev" && myPass == "12345"
  24.         {
  25.             //intent
  26.             let flagVC = storyboard?.instantiateViewController(withIdentifier: "vcFlag")
  27.             //startActivity
  28.             present(flagVC!, animated: true, completion: nil)
  29.         }
  30.         else
  31.         {
  32.             self.showToast(message: "error in user name or password")
  33.         }
  34.         txtUser.text = ""
  35.         txtPassword.text = ""
  36.     }
  37. }
  38.  
  39. extension UIViewController{
  40.     func showToast(message: String)
  41.     {
  42.         let toastLabel = UILabel(frame: CGRect(x: self.view.frame.size.width/2, y: self.view.frame.size.height-100, width: 150, height: 35))
  43.         toastLabel.backgroundColor = UIColor.black.withAlphaComponent(0.6)
  44.         toastLabel.textColor = UIColor.white
  45.         toastLabel.textAlignment = .center
  46.         toastLabel.text = message
  47.         toastLabel.alpha = 1
  48.         toastLabel.layer.cornerRadius = 10
  49.         toastLabel.clipsToBounds = true
  50.         self.view.addSubview(toastLabel)
  51.         UIView.animate(withDuration: 4.0, delay: 0.1, options: .curveEaseOut, animations: {
  52.             toastLabel.alpha = 0.0
  53.         }, completion: { (isCompleted) in
  54.             toastLabel.alpha = CGFloat(0.0)
  55.             })
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement