UIAlertView

 

#import "ViewController.h"

 

@interface ViewController ()

 

@end

 

@implementation ViewController

 

- (void)viewDidLoad {

 

 

 UIButton *button1=[UIButton buttonWithType:UIButtonTypeCustom];

    button1.backgroundColor=[UIColor greenColor];

    button1.frame=CGRectMake(100, 100, 120, 50);

    [button1 addTarget:self action:@selector(showMyAlertView:) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:button1];

 }

 

 

-(void)showMyAlertView:(id)sender{

    //初始化一个UIAlertView

    UIAlertView *alertView1=[[UIAlertView alloc]initWithTitle:@"warning" message:@"当前无网络连接" delegate:self cancelButtonTitle:@"cansel" otherButtonTitles:nil, nil];

    alertView1.tag=100;//设置tag值

    [alertView1 addButtonWithTitle:@"确定"];

    //添加提示框展示的按钮;也可以在otherButtonTitles:后面直接添加有的只有一个取消,那么otherButtonTitles:后面写一个nil就可以了,

 

//    alertView1.title=@"alertView";//设置提示框标题,设置后警告变为alertView

//    alertView1.message=@"还是那个提示框的message";

//    NSLog(@"%d",alertView1.visible);//提示框是否可见(只读)

//    NSLog(@"%d",(int)alertView1.numberOfButtons);//按钮个数

//    NSLog(@"%@",[alertView1 buttonTitleAtIndex:0]);//获取提示框指定按钮的标题

//    NSLog(@"%d",(int)[alertView1 cancelButtonIndex]);//取消按钮的索引

//    NSLog(@"%d",(int)alertView1.firstOtherButtonIndex);//第一个按钮的索引

    

//    alertView1.alertViewStyle=UIAlertViewStyleLoginAndPasswordInput;//带有明文输入框

    //    UIAlertViewStyleDefault = 0,//无

    //    UIAlertViewStyleSecureTextInput,//明文

    //    UIAlertViewStylePlainTextInput,//暗文

    //    UIAlertViewStyleLoginAndPasswordInput//一明一暗

//    UITextField *text1=[alertView1 textFieldAtIndex:0];//获取第一个输入框

//    UITextField *text2=[alertView1 textFieldAtIndex:1];//获取第二个输入框

//    text1.placeholder=@"请输入账号";

//    text2.placeholder=@"请输入密码";

//    text1.text=@"http://";//输入网址以便连接

//    text1.clearButtonMode=UITextFieldViewModeWhileEditing;

    //让提示框展示

    [alertView1 show];

    

 

}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

{

    NSLog(@"hello %d",(int)buttonIndex);

    switch (buttonIndex) {

        case 0:

            NSLog(@"调用0");

            break;

        case 1:

        {

            NSLog(@"调用1");

            UIAlertView *alertView1=[[UIAlertView alloc]initWithTitle:@"警告" message:@"当前无网络连接" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:nil, nil];

            [alertView1 addButtonWithTitle:@"确定"];

            [alertView1 show];

        }

            break;

        default:

            break;

    }

 }

 

转载于:https://www.cnblogs.com/OIMM/p/4699113.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值