iOS Uialertcontroller Frame (iOS 9.0 replaces the Uialertview frame and uiactionsheet down frame)

Source: Internet
Author: User
After iOS 9.0, Apple officially announced no longer or no recommendation to use Uialertview and uiactionsheet to be replaced by Uialertcontroller. It's easy to use a controller to combine the two. The following is a common method of Uialertview

#import "RootViewController.h"


@interface Rootviewcontroller ()


@end


@implementation Rootviewcontroller


-(void) Viewdidload {

[Super Viewdidload];

Create a button click on the show Bomb frame

UIButton *button = [UIButton buttonwithtype: (Uibuttontypecustom)];

Button.frame = CGRectMake (100, 100, 100, 100);

Add a click method to the button

[Button addtarget:self action: @selector (Actionbutton:) forControlEvents: (UIControlEventTouchUpInside)];

Button.backgroundcolor = [Uicolor Bluecolor];

[Self.view Addsubview:button];

}

Button's Click Method

-(void) Actionbutton: (UIButton *) button

{

Initializes a Uialertcontroller

Parameter Preferredstyle: is the Ialertcontroller style

Uialertcontrollerstylealert created out of the equivalent of Uialertview

Uialertcontrollerstyleactionsheet created out of the equivalent of Uiactionsheet

Uialertcontroller *alertcontroller = [Uialertcontroller alertcontrollerwithtitle:@ "hint" message:@ "Static" PreferredStyle: ( Uialertcontrollerstylealert)];


Create a button

Uialertaction *okaction = [uialertaction actionwithtitle:@ "OK" style: (Uialertactionstyledefault) handler:^ ( Uialertaction *action) {

NSLog (@ "Pay attention to learning");

}];

Create a button

Note the Cancel button can only add one

Uialertaction *cancelaction = [uialertaction actionwithtitle:@ "Cancel" style: (Uialertactionstylecancel) handler:^ ( Uialertaction *action) {

Click on the button after the method directly in here to write

NSLog (@ "Pay attention to learning");

}];


Create a warning button

Uialertaction *structlaction = [uialertaction actionwithtitle:@ warning Style: (uialertactionstyledestructive) Handler: ^ (uialertaction *action) {

NSLog (@ "Pay attention to learning");

//    }];

//

Add a button to add a button to a Uialertcontroller object

[Alertcontroller addaction:okaction];

[Alertcontroller addaction:cancelaction];

[Alertcontroller addaction:structlaction];


You can add a text box only if alert

[Alertcontroller addtextfieldwithconfigurationhandler:^ (Uitextfield *textfield) {

Textfield.placeholder = @ "username";

Textfield.securetextentry = YES;

}];


Remove text

Uitextfield *text = AlertController.textFields.firstObject;

Uialertaction *action = AlertController.actions.firstObject;


The method of Uialertcontroller mode is equivalent to Uialertview show

[Self Presentviewcontroller:alertcontroller animated:yes completion:nil];

}






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.