Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // ViewController.swift
- // MyDialog
- //
- // Created by HackerU on 26/10/2016.
- // Copyright © 2016 HackerU. All rights reserved.
- //
- import UIKit
- class ViewController: UIViewController {
- @IBOutlet weak var darinDialog: UIView!
- @IBOutlet weak var ttlHello: UILabel!
- override func viewDidLoad() {
- super.viewDidLoad()
- // Do any additional setup after loading the view, typically from a nib.
- }
- override func didReceiveMemoryWarning() {
- super.didReceiveMemoryWarning()
- // Dispose of any resources that can be recreated.
- }
- @IBAction func showDarin(_ sender: UIButton) {
- ttlHello.text="Hello Darin!!!";
- darinDialog.isHidden=false;
- print ("show darin");
- }
- @IBAction func closeDarin(_ sender: UIButton) {
- darinDialog.isHidden=true;
- }
- @IBAction func simpleDialog(_ sender: UIButton) {
- //build AlertDialog with UIAlertController object
- let dialog = UIAlertController(title: "Haalan Sveta", message: "Good Night and dont worry", preferredStyle: UIAlertControllerStyle.alert);
- //create cancel button
- let btnAction = UIAlertAction(title: "Sababa", style: UIAlertActionStyle.cancel, handler: nil);
- //add the button to the dialog
- dialog.addAction(btnAction);
- //show the dialog
- show(dialog, sender:self);
- }
- @IBAction func myDefInput(_ sender: UIButton) {
- //Build AlertDialog with UIAlertController object
- let dialog = UIAlertController(title: "Yuli the Great", message: "we need more pepole like Yuli", preferredStyle: .alert);
- //add TextField
- dialog.addTextField(configurationHandler: nil);
- //add positive button (sababa)
- func okHandler(_ eventTarget:UIAlertAction)
- {
- //called when user clicked Sababa
- print (dialog.textFields![0].text!);
- }
- //add positive action to our dialog
- dialog.addAction(UIAlertAction(title: "Sababa", style: .default, handler: okHandler));
- //add negative action to our dialog
- dialog.addAction(UIAlertAction(title: "LO SABABA", style: .cancel, handler: nil));
- //show dialog
- show(dialog, sender:self);
- }
- @IBAction func conf1AlertCtrl(_ sender: UIButton) {
- //create AlertDialog with UIAlertContreoller object
- let dialog = UIAlertController(title: "Liran", message: nil, preferredStyle: .alert);
- //create a TextField
- var uName:UITextField!; //configurated textField container
- dialog.addTextField(configurationHandler: {(input:UITextField) in
- input.placeholder="Type your buddy"; //add some configuration
- input.clearButtonMode=UITextFieldViewMode.whileEditing;
- uName=input; //assing addTextField(input) to predefinded container (uName)
- });
- dialog.addAction(UIAlertAction(title: "Sababa", style: .default, handler: {positveButton in
- print (uName.text!); //read from uName
- }));
- dialog.addAction(UIAlertAction(title: "No sababa", style: .cancel, handler: nil));
- show(dialog, sender: self);
- }
- @IBAction func conf2AlertCtrl(_ sender: UIButton) {
- //simulator for login screen
- let dialog = UIAlertController(title: "Please sign in...", message: nil, preferredStyle: .alert);
- var uName,Upass:UITextField!;
- dialog.addTextField(configurationHandler: {input in
- input.placeholder="Type user name";
- input.clearButtonMode=UITextFieldViewMode.whileEditing;
- uName=input;
- });
- dialog.addTextField(configurationHandler: {input in
- input.placeholder="Enter password";
- input.isSecureTextEntry=true;
- Upass=input;
- });
- dialog.addAction(UIAlertAction(title: "Login", style: .default, handler: {Orya in
- if uName.text=="oorya" && Upass.text=="321"
- {
- self.ttlHello.text="Hello my master!!!";
- self.darinDialog.isHidden=false;
- }}));
- dialog.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil));
- show(dialog, sender:self);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement