zoukankan      html  css  js  c++  java
  • UIAlertControlle的基本用法

     使用UIAlertController需要三步

    1、实例化alert:alertControllerWithTitle

    2、实例化按钮:actionWithTitle

    3、显示alertController:presentViewController

    下面是实现上面三步的简单代码

    //实例化alert:alertControllerWithTitle

        UIAlertController *alert= [UIAlertController alertControllerWithTitle:@"提示" message:@"请输入账号和密码" preferredStyle:UIAlertControllerStyleAlert];

        //实例化按钮actionWithTitle

        [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * action) {

            NSLog(@"%@",[alert.textFields.firstObject text]);

        }]];

        //实例化按钮actionWithTitle

        [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];

        //添加文本框

        [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {

            textField.text=self.title;

        }];

        [alert addTextFieldWithConfigurationHandler:^(UITextField * textField) {

            //密文显示

            textField.secureTextEntry=YES;

        }];

        //显示alert

        [self presentViewController:alert animated:YES completion:nil];

    这是代码实现的结果

  • 相关阅读:
    超赞!不容错过的5款实用网页开发和设计工具
    如何从平面设计转行到UI设计?
    线段树
    RMQ
    Splay
    Treap
    *模板--矩阵
    最小生成树
    hash
    ac自动机
  • 原文地址:https://www.cnblogs.com/layios/p/5263678.html
Copyright © 2011-2022 走看看