iOS warning and prompt dialog box

Source: Internet
Author: User

During the development of iOS, various reminders are inevitably used to alert the user to the current operation, either for warning or for data buffering.

This article describes a reminder to complete three states using the Uialertcontroller and uialertaction two classes.

Here we first use Uialertcontroller to create a prompt dialog box, which can be created quickly by factory method, with only one style of parameter uialertcontrollerstyle: Uialertcontrollerstylealert.

Once you've filled out the title and content of the hint, you can use Uialertaction to create a specific button behavior. There are three styles of parameter Uialertactionstyle, Uialertactionstyledefault (normal), Uialertactionstylecancel (cancel), Uialertactionstyledestructive (Warning (destructive)). The default state is a normal blue font, the font is bold when the status is canceled, and the warning state font turns red. When only one behavior object is added, the behavior object will appear below the Uialertcontroller object, add 2, display side by side, add 3 or more, and display in columns.

You can easily add the following code in any of the event response functions, and add the statement in the block statement that executes when the user chooses the appropriate option.

    //use Uialertcontroller to create a prompt dialog box with only the title and information//Uialertcontrollerstyle has only one style: Uialertcontrollerstylealert//use Uialertacion to create a specific behavior, and add three columns to display by column//Uialertactionstyle has three styles, normal, canceled, warning (destructive)//Uialertactionstyledefault, Uialertactionstylecancel (font bold display), Uialertactionstyledestructive (font red display)Uialertcontroller*alert = [Uialertcontroller alertcontrollerwithtitle:@"title"Message@"MessageBox"Preferredstyle:uialertcontrollerstylealert]; Uialertaction*action1 = [Uialertaction actionwithtitle:@"Confirm"Style:uialertactionstyledefault handler:^ (Uialertaction *action)    {    }]; Uialertaction*action2= [uialertaction Actionwithtitle:@"Cancel"Style:uialertactionstylecancel handler:^ (Uialertaction *action)    {    }]; Uialertaction*action3= [uialertaction Actionwithtitle:@"Warning"Style:uialertactionstyledestructive handler:^ (Uialertaction *action)        {    }];    [Alert Addaction:action1];    [Alert Addaction:action2];    [Alert Addaction:action3]; [Self presentviewcontroller:alert animated:yes completion:^{    }];

iOS warning and prompt 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.