IOS pop-up window Alertview use

Source: Internet
Author: User

Transferred from: http://blog.it985.com/4321.html

Alertview is the pop-up window notification box that comes with iOS, let's look at the default style

Directly below the code

12345 - (void)delete{//弹窗UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"是否删除?"message:nil delegate:self cancelButtonTitle:@"取消"otherButtonTitles:@"确定", nil];[alertView show];}

If you want to make one button below,

12345 - (void)delete{//弹窗UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"是否删除?"message:nil delegate:self cancelButtonTitle:@"确定"otherButtonTitles:nil];[alertView show];}

Click OK or Cancel button after pop-up window to add an event.

12345678910 - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex//点击弹窗按钮后{    NSLog(@"buttonIndex:%ld",(long)buttonIndex);    if (buttonIndex == 0) {//取消        NSLog(@"取消");    }else if (buttonIndex == 1){//确定        NSLog(@"确定");    }}

The buttonindex of the leftmost button is 0, and the right button Buttonindex in turn.

Now for the use of custom styles, Alertview can not only make text-style pop-up windows, but also make picture styles or pop-up windows with Pickerview, now for example with editable text box pop-up windows
Check it out first.

Introduction of libraries before use
If you don't have a library, download the library first
Customios7alertview

1 #import "CustomIOS7AlertView.h"

Directly on the code

1234567891011121314151617181920212223242526272829303132333435 - (void)alertViewUser{    CustomIOS7AlertView *alertView = [[CustomIOS7AlertView alloc] init];    [alertView setButtonTitles:[NSMutableArray arrayWithObjects:@"上一个", @"确定", @"下一个", nil]];    UIView *demoView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 290, 120)];    UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 180, 20)];    title.text = @"请填写姓名";    [demoView addSubview:title];    UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(10, 50, 270, 30)];    textField.backgroundColor = [UIColor whiteColor];    textField.returnKeyType = UIReturnKeyDone;    textField.delegate = self;    [demoView addSubview:textField];    [alertView setContainerView:demoView];//把demoView添加到自定义的alertView中    //这里是点击按钮之后触发的事件    [alertView setOnButtonTouchUpInside:^(CustomIOS7AlertView *alertView, int buttonIndex) {        if (buttonIndex==0) {//上一个            NSLog(@"上一个");        } else if (buttonIndex==1) {//确定            NSLog(@"确定");            NSLog(@"texeValue:%@",textField.text);        } else if (buttonIndex == 2){//先保存数据,然后跳到下一个            NSLog(@"下一个");        }    }];    [alertView show];}

It is important to note that the method of adding DemoView to Alertview is "[Alertview Setcontainerview:demoview];"
And clicking on the Alertview triggered event is also indicated in the comment above. You can paste the code into the past and use it directly.
If you want to add pictures or other can be added directly inside the DemoView. You can control the size.

Permanent address of this article: http://blog.it985.com/4321.html
This article is from IT985 blog, please indicate the source and corresponding link when reproduced.

IOS pop-up window Alertview use

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.