Advertisement
Guest User

alert dialog examples

a guest
Oct 26th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 4.30 KB | None | 0 0
  1. //
  2. //  ViewController.swift
  3. //  MyDialog
  4. //
  5. //  Created by HackerU on 26/10/2016.
  6. //  Copyright © 2016 HackerU. All rights reserved.
  7. //
  8.  
  9. import UIKit
  10.  
  11. class ViewController: UIViewController {
  12.  
  13.    
  14.     @IBOutlet weak var darinDialog: UIView!
  15.     @IBOutlet weak var ttlHello: UILabel!
  16.    
  17.     override func viewDidLoad() {
  18.         super.viewDidLoad()
  19.         // Do any additional setup after loading the view, typically from a nib.
  20.     }
  21.  
  22.     override func didReceiveMemoryWarning() {
  23.         super.didReceiveMemoryWarning()
  24.         // Dispose of any resources that can be recreated.
  25.     }
  26.  
  27.     @IBAction func showDarin(_ sender: UIButton) {
  28.         ttlHello.text="Hello Darin!!!";
  29.         darinDialog.isHidden=false;
  30.         print ("show darin");
  31.     }
  32.  
  33.     @IBAction func closeDarin(_ sender: UIButton) {
  34.         darinDialog.isHidden=true;
  35.     }
  36.    
  37.     @IBAction func simpleDialog(_ sender: UIButton) {
  38.         //build AlertDialog with UIAlertController object
  39.         let dialog = UIAlertController(title: "Haalan Sveta", message: "Good Night and dont worry", preferredStyle: UIAlertControllerStyle.alert);
  40.         //create cancel button
  41.         let btnAction = UIAlertAction(title: "Sababa", style: UIAlertActionStyle.cancel, handler: nil);
  42.         //add the button to the dialog
  43.         dialog.addAction(btnAction);
  44.         //show the dialog
  45.         show(dialog, sender:self);
  46.     }
  47.    
  48.     @IBAction func myDefInput(_ sender: UIButton) {
  49.         //Build AlertDialog with UIAlertController object
  50.         let dialog = UIAlertController(title: "Yuli the Great", message: "we need more pepole like Yuli", preferredStyle: .alert);
  51.         //add TextField
  52.         dialog.addTextField(configurationHandler: nil);
  53.         //add positive button (sababa)
  54.         func okHandler(_ eventTarget:UIAlertAction)
  55.         {
  56.             //called when user clicked Sababa
  57.             print (dialog.textFields![0].text!);
  58.         }
  59.         //add positive action to our dialog
  60.         dialog.addAction(UIAlertAction(title: "Sababa", style: .default, handler: okHandler));
  61.         //add negative action to our dialog
  62.         dialog.addAction(UIAlertAction(title: "LO SABABA", style: .cancel, handler: nil));
  63.         //show dialog
  64.         show(dialog, sender:self);
  65.     }
  66.    
  67.     @IBAction func conf1AlertCtrl(_ sender: UIButton) {
  68.         //create AlertDialog with UIAlertContreoller object
  69.         let dialog = UIAlertController(title: "Liran", message: nil, preferredStyle: .alert);
  70.         //create a TextField
  71.         var uName:UITextField!; //configurated textField container
  72.         dialog.addTextField(configurationHandler: {(input:UITextField) in
  73.             input.placeholder="Type your buddy"; //add some configuration
  74.             input.clearButtonMode=UITextFieldViewMode.whileEditing;
  75.             uName=input; //assing addTextField(input) to predefinded container (uName)
  76.         });
  77.        
  78.         dialog.addAction(UIAlertAction(title: "Sababa", style: .default, handler: {positveButton in
  79.             print (uName.text!); //read from uName
  80.            
  81.         }));
  82.            
  83.         dialog.addAction(UIAlertAction(title: "No sababa", style: .cancel, handler: nil));
  84.             show(dialog, sender: self);
  85.     }
  86.    
  87.     @IBAction func conf2AlertCtrl(_ sender: UIButton) {
  88.         //simulator for login screen
  89.         let dialog = UIAlertController(title: "Please sign in...", message: nil, preferredStyle: .alert);
  90.         var uName,Upass:UITextField!;
  91.         dialog.addTextField(configurationHandler: {input in
  92.             input.placeholder="Type user name";
  93.             input.clearButtonMode=UITextFieldViewMode.whileEditing;
  94.             uName=input;
  95.         });
  96.         dialog.addTextField(configurationHandler: {input in
  97.             input.placeholder="Enter password";
  98.             input.isSecureTextEntry=true;
  99.             Upass=input;
  100.         });
  101.         dialog.addAction(UIAlertAction(title: "Login", style: .default, handler: {Orya in
  102.             if uName.text=="oorya" && Upass.text=="321"
  103.             {
  104.                 self.ttlHello.text="Hello my master!!!";
  105.                 self.darinDialog.isHidden=false;
  106.             }}));
  107.         dialog.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil));
  108.         show(dialog, sender:self);
  109.        
  110.     }
  111.    
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement