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