美文网首页
IOS9+基础之警报框弹出和操作表弹出

IOS9+基础之警报框弹出和操作表弹出

作者: Johnson_9d92 | 来源:发表于2021-06-10 08:41 被阅读0次

IOS9+基础之警报框弹出和操作表弹出

Xnip2021-06-03_16-38-53.jpg Xnip2021-06-03_16-40-34.jpg Xnip2021-06-03_16-39-14.jpg

代码如下

//
//  ViewController.m
//  001-UIAlertView
//
//  Created by lujun on 2021/6/3.
//

#import "ViewController.h"

@interface ViewController ()
- (IBAction)rightClick:(id)sender;

@end

@implementation ViewController


- (IBAction)clck2:(id)sender {
    
    
    
//    UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"标题" message:@"消息" delegate:self cancelButtonTitle:@"取消按钮" otherButtonTitles:@"其他按钮标题", nil];
//
//    [alert show];
    
    //1.创建UIAlertControler
  
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"标题" message:@"这是一些信息" preferredStyle:UIAlertControllerStyleAlert];
    /*
     参数说明:
     Title:弹框的标题
     message:弹框的消息内容
     preferredStyle:弹框样式:UIAlertControllerStyleAlert
     */
    
    //2.添加按钮动作
    //2.1 确认按钮
    UIAlertAction *conform = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        NSLog(@"点击了确认按钮");
    }];
    //2.2 取消按钮
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        NSLog(@"点击了取消按钮");
    }];
    //2.3 还可以添加文本框 通过 alert.textFields.firstObject 获得该文本框
//    [alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
//       textField.placeholder = @"请填写您的反馈信息";
//  }];
 
    //3.将动作按钮 添加到控制器中
    [alert addAction:conform];
    [alert addAction:cancel];
    
    //4.显示弹框
    [self presentViewController:alert animated:YES completion:nil];
    
    
}


- (IBAction)leftClick:(id)sender {
    
    
//    UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"标题" message:@"消息" delegate:self cancelButtonTitle:@"取消按钮" otherButtonTitles:@"其他按钮标题", nil];
//
//    [alert show];
    
    //1.创建UIAlertControler
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"标题" message:@"这是一些信息" preferredStyle:UIAlertControllerStyleAlert];
    /*
     参数说明:
     Title:弹框的标题
     message:弹框的消息内容
     preferredStyle:弹框样式:UIAlertControllerStyleAlert
     */
    
    //2.添加按钮动作
    //2.1 确认按钮
    UIAlertAction *conform = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        NSLog(@"点击了确认按钮");
    }];
    //2.2 取消按钮
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        NSLog(@"点击了取消按钮");
    }];
    //2.3 还可以添加文本框 通过 alert.textFields.firstObject 获得该文本框
    [alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
       textField.placeholder = @"请填写您的反馈信息";
  }];
 
    //3.将动作按钮 添加到控制器中
    [alert addAction:conform];
    [alert addAction:cancel];
    
    //4.显示弹框
    [self presentViewController:alert animated:YES completion:nil];
    
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
}


- (IBAction)rightClick:(id)sender {
    //1.创建Controller
    UIAlertController *alertSheet = [UIAlertController alertControllerWithTitle:@"标题" message:@"一些信息" preferredStyle:UIAlertControllerStyleActionSheet];
    /*
     参数说明:
     Title:弹框的标题
     message:弹框的消息内容
     preferredStyle:弹框样式:UIAlertControllerStyleActionSheet
     */
    
    //2.添加按钮动作
    UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"项目1" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        NSLog(@"点击了项目1");
    }];
    UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"项目2" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        NSLog(@"点击了项目2");
    }];
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        NSLog(@"点击了取消");
    }];
    //3.添加动作
    [alertSheet addAction:action1];
    [alertSheet addAction:action2];
    [alertSheet addAction:cancel];
    
    //4.显示sheet
    [self presentViewController:alertSheet animated:YES completion:nil];
    
    
}
@end

相关文章

  • IOS9+基础之警报框弹出和操作表弹出

    IOS9+基础之警报框弹出和操作表弹出 代码如下

  • 小程序弹出框详解

    小程序弹出框详解 操作菜单——wx.showActionSheet(OBJECT) 弹出框 指定modal弹出 达...

  • vue-弹出框组件

    创建一个公用的弹出框组件,包括消息弹出框,确认弹出框,自定义内容弹出框 一、创建 1、创建一个基础弹出框:dial...

  • 5、bootstrap模态框,弹出框(一)

    项目中用到了模态框和弹出框。模态框:在操作错误或需要提示时弹出,遮罩整个页面,一般显示在整个页面的正中间弹出框:可...

  • swal的几种用法

    1,弹出提示框,点击确认,进行下一步操作 2,仅弹出提示框 3,仅弹出提示框,简单写法

  • V说新版震撼来袭

    和上个版本不同的是,这一次的多选操作都是,左下角弹出。选择了一个后会弹出单选操作框。多选以后弹出多选对话框。 强烈...

  • js基础-语法

    1.基础语法 alert('弹出提示框') prompt('弹出让用户输入的输入框') console.log('...

  • bootstrap弹出层校验设置

    1、显示弹出框方法操作注意顺序

  • bootstrap模态框多层嵌套,背景滚动

    问题:在弹出模态框A的基础上,弹出模态框B,关闭模态框B之后,模态框A不能滚动(由于A模块框内容) 造成的原因:遮...

  • BootStrap[第十六章:弹出框和警告框插件]

    一.弹出框 弹出框即点击一个元素弹出一个包含标题和内容的容器。 弹出框插件有很多属性来配置提示的显示,具体如下: ...

网友评论

      本文标题:IOS9+基础之警报框弹出和操作表弹出

      本文链接:https://www.haomeiwen.com/subject/lmwzsltx.html