Swift Uialertview/uiactionsheet

Source: Internet
Author: User
Tags deprecated

Uialertview


A warning displays a warning message that the user displays a brief and informational message to the user. The warning view conveys important information about an application or device, interrupts the user, and asks them to stop the choice action they are making or dismiss the alert. For example, iOS uses alerts to warn users that the battery is running low, so they can disconnect the power adapter when their work is interrupted. The alert view appears at the top of the application's content and must be manually released by the user before it can be restored with the application.

Use of Uialertview1. Style 1


<span style= "FONT-SIZE:14PX;" >//default Style new control mode 1    func initUIAlertView1 () {let        alertView1 = uialertview.init (title: "Style 1", Message: "Test" , Delegate:self, Cancelbuttontitle: "Cancel", Otherbuttontitles: "OK", "button 3")//Available in IOS 2.0 and later. Deprecated in IOS 9.0.        Alertview1.show ()    }</span>

2. Style 2


Func initUIAlertView2 () {let        alertView2 = Uialertview.init ()        alertview2.title = "Style 2"        alertview2.message = "Test"        alertview2.addbuttonwithtitle ("Cancel")//Add "Cancel" button first, it's index = 0        alertview2.addbuttonwithtitle ("OK")// index = 1        alertview2.delegate = self        alertview2.show ()    }

above Style 1 and Style 2 is the same, just two different ways to create a new control, and Style 1 than Style 2 has one more button.

3. Style 3


Func initUIAlertView3 () {let        alertView3 = Uialertview.init ()        Alertview3.alertviewstyle = Uialertviewstyle.securetextinput//ciphertext        alertview3.title = "Securetextinput"        alertview3.addbuttonwithtitle ( "OK")        alertview3.delegate = self        alertview3.show ()    }

4. Style 4


Func initUIAlertView4 () {let        alertView4 = Uialertview.init ()        Alertview4.alertviewstyle = Uialertviewstyle.plaintextinput  //non-ciphertext        alertview4.title = "Plaintextinput"        Alertview4.addbuttonwithtitle ("OK")        alertview4.delegate = self        alertview4.show ()    }

Style 3 and style 4, the basic is the same, the knowledge view in the middle of the textfiled one is a cipher is not.

5. Style 5


    Func initUIAlertView5 () {let        alertView5 = Uialertview.init ()        Alertview5.alertviewstyle = Uialertviewstyle.loginandpasswordinput  //login user name and password input style        alertview5.title = "Loginandpasswordinput"        Alertview5.addbuttonwithtitle ("OK")        alertview5.delegate = self        alertview5.show ()    }

uialertviewdelegateAgent, general use only need to implement there is a way to do it.

Func Alertview (Alertview:uialertview, Clickedbuttonatindex buttonindex:int) {        print ("title = \ ( Alertview.buttontitleatindex (buttonindex)) Buttonindex = \ (buttonindex))//Print button title and index        if Alertview.alertviewstyle = = Uialertviewstyle.loginandpasswordinput {            print ("\ (Alertview.textfieldatindex (0)?. Text)//Print input            ("\ (Alertview.textfieldatindex (1)?. Text)//print input Contents        }        else{            print ("\ (Alertview.textfieldatindex (0)?. Text)//print input Contents        }    }


UiactionsheetUiactionsheet is used in the same way as Uialertview, just two different controls, and a display style.


Use of Uiactionsheet

1. Style 1


This is the system default style

<span style= "FONT-SIZE:14PX;" > Func InitUIActionSheet1 () {let        ActionSheet1 = uiactionsheet.init (title: "Uiactionsheet", Delegate:self, Cancelbuttontitle: "Cancel", Destructivebuttontitle: "OK")//Available in IOS 2.0 and later. Deprecated in IOS 8.3.        Actionsheet1.showinview (self.view)    }</span>

2. Style 2


Func InitUIActionSheet2 () {        Let ActionSheet2 = Uiactionsheet.init ()        actionsheet2.title = "I am title"        Actionsheet2.addbuttonwithtitle ("OK")        Actionsheet2.addbuttonwithtitle ("Cancel")        actionsheet2.delegate = self        Actionsheet2.showinview (self.view)    }

uiactionsheetdelegate
    Func Actionsheet (Actionsheet:uiactionsheet, Clickedbuttonatindex buttonindex:int) {        print ("title = \ ( Actionsheet.buttontitleatindex (buttonindex)) Buttonindex = \ (buttonindex))//Print button title and Index    }

Demo Interface

The entire interface is done with 7 buttons to trigger the 7 styles of this two control



<span style= "FONT-SIZE:14PX;"  > @IBAction func btnclick (Sender:uibutton) {let        tag = Sender.tag        //Print button tag and title print        ("tag = \ (tag) title = \ (Sender.titlelabel?. Text) ")        switch Tag {case        1:            self.inituialertview1 () break case        2:            self.inituialertview2 () Break Case        3:            self.inituialertview3 () break Case        4:            self.inituialertview4 ()            Break Case        5:            self.inituialertview5 ()            break                    default:break                    }    }</span>

<span style= "FONT-SIZE:14PX;"  > @IBAction func btnClick2 (Sender:uibutton) {let        tag = Sender.tag        //Print button tag and title print        ("tag = \ (tag) title = \ (Sender.titlelabel?. Text) ")        switch Tag {case        1:            Self.inituiactionsheet1 () break case        2:            Self.inituiactionsheet2 ()            break        default:break        }    }</span>


Swift Uialertview/uiactionsheet

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.