Uialertcontroller class--alert Bullet Box 3 (Text dialog box)

Source: Internet
Author: User

First, the effect

Second, the realization

-(void) Touchesbegan: (Nsset<uitouch *> *) touches withevent: (Uievent *) event

{

[Self alertTest3];

}

/**

* Text dialog box

*/

-(void) alertTest3

{

1. Create Uialertcontroller

Uialertcontroller *alertcontroller = [Uialertcontroller

alertcontrollerwithtitle:@ "Text dialog box"

message:@ "Login and Password dialog box example"

Preferredstyle:uialertcontrollerstylealert];

2. Add Text dialog box

/**

Benefits:

1. You can add any of the Uitextfield objects to the dialog box

2. All Uitextfield features can be used

*/

[Alertcontroller addtextfieldwithconfigurationhandler:^ (Uitextfield * _nonnull TextField) {

Textfield.placeholder = @ "Login";

}];

[Alertcontroller addtextfieldwithconfigurationhandler:^ (Uitextfield * _nonnull TextField) {

Textfield.placeholder = @ "password";

Textfield.securetextentry = yes;//Ciphertext

}];

3. Create a Uialertaction instance

Uialertaction *okaction = [uialertaction actionwithtitle:@ "Good" Style:uialertactionstyledefault handler:^ ( Uialertaction * _nonnull action) {//click the "OK" button, let the program read the value in the text box, and then do something

Uitextfield *login = AlertController.textFields.firstObject;

Uitextfield *password = AlertController.textFields.lastObject;

}];

Uialertaction *cancelaction = [uialertaction actionwithtitle:@ "Cancel" Style:uialertactionstylecancel handler:^ ( Uialertaction * _nonnull action) {

}];

4.UIAlertAction instance added to Alertcontroller

[Alertcontroller addaction:okaction];

[Alertcontroller addaction:cancelaction];

5. Display the View Controller

[Self Presentviewcontroller:alertcontroller animated:yes completion:^{

}];

}

Uialertcontroller class--alert Bullet Box 3 (Text dialog box)

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.