IOS开发中的弹框综述
2016-09-14 00:42
316 查看
题记————
人生在世,淡定看世界。
感受生活,从不说疲惫,因为卡里的存款还不够多。
体验生活,从不说难受,因为肩上的责任不能丢。
感悟生活,从不说后退,因为脚下的路依然要走
2-2 UIAlertController
显示效果:
可以看到在这里同时也设置了代理,只是为了监听弹出框的点击事件 ,当然同时要实现协议(或者称为遵守)
同时复写代理 监听回调方法
实现方式:
可以看到在添加按钮的时候同时添加了一个对应的block函数,来监听对应的按钮的点击事件
实现:
与方式一相比较,基本实现方式是一致的,不同的是在创建View的时候,设置的弹出方式preferredStyle不同 ,默认的方式是从视图中间显示,设置弹出方式为UIAlertControllerollerStyleActionSheet,则实现了弹框从底部弹出的效果
对应按钮的点击事件则在设置的对应的Block函数中实现
人生在世,淡定看世界。
感受生活,从不说疲惫,因为卡里的存款还不够多。
体验生活,从不说难受,因为肩上的责任不能丢。
感悟生活,从不说后退,因为脚下的路依然要走
1、预览
2、弹出框的基本实现方式
2-1 UIAlertView2-2 UIAlertController
3、AlertView弹出方式简述
3-1 实现方式//AlertView中央弹出 - (IBAction)AlertViewBottomShow:(id)sender { //创建 UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"提示" message:@"从底部弹出" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确认", nil]; //添加代理 alertView.delegate = self; //显示 [alertView show]; }
显示效果:
可以看到在这里同时也设置了代理,只是为了监听弹出框的点击事件 ,当然同时要实现协议(或者称为遵守)
#import "ViewController.h" @interface ViewController () <UIAlertViewDelegate> @end
同时复写代理 监听回调方法
//alertView 代理回调 -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ NSLog(@"%lu",buttonIndex); }那么在这里就可以监听到对应的点击按钮,就可以做相应的操作
4、UIAlertController弹出方式
4-1 视图中央弹出
实现方式:
//显示方式为直接从视图中央弹出 - (IBAction)clickUIAlertControllerFunction:(id)sender { //创建 UIAlertController *controll = [UIAlertController alertControllerWithTitle:@"提示" message:@"点击监听提示" preferredStyle:UIAlertControllerStyleAlert]; //添加取消按钮 并设置Block [controll addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { NSLog(@"CLICK 取消"); }]]; //添确认消按钮 并设置Block [controll addAction:[UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { NSLog(@"CLICK 确认"); }]]; //弹出 [self presentViewController:controll animated:NO completion:nil]; }
可以看到在添加按钮的时候同时添加了一个对应的block函数,来监听对应的按钮的点击事件
4-2 、从视图的底部弹出显示框
实现:
//AlertController底部弹出 - (IBAction)AlertControllerBottomShow:(id)sender { //创建 UIAlertController *controller = [UIAlertController alertControllerWithTitle:@"提示" message:@"底部弹出" preferredStyle:UIAlertControllerStyleActionSheet]; //添加按钮一 [controller addAction:[UIAlertAction actionWithTitle:@"选择一" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { NSLog(@"CLICK 选择一"); }]]; //添加按钮一 [controller addAction:[UIAlertAction actionWithTitle:@"选择二" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { NSLog(@"CLICK 选择二"); }]]; //添加按钮三 [controller addAction:[UIAlertAction actionWithTitle:@"选择三" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { NSLog(@"CLICK 选择三"); }]]; //显示 [self presentViewController:controller animated:YES completion:nil]; }
与方式一相比较,基本实现方式是一致的,不同的是在创建View的时候,设置的弹出方式preferredStyle不同 ,默认的方式是从视图中间显示,设置弹出方式为UIAlertControllerollerStyleActionSheet,则实现了弹框从底部弹出的效果
对应按钮的点击事件则在设置的对应的Block函数中实现
5、向弹出框中添加输入框
//创建 UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"文本对话框" message:@"登录和密码对话框示例" preferredStyle:UIAlertControllerStyleAlert]; //向视图中添加第一个输入框 [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField){ textField.placeholder = @"用户名"; }]; //向视图中添加第二个输入框 [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) { textField.placeholder = @"电话"; textField.secureTextEntry = YES; }]; //确认 UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { //获取第一个输入框 UITextField *login = alertController.textFields.firstObject; //获取第二个输入框 UITextField *password = alertController.textFields.lastObject; NSLog(@"%@%@",login.text,password.text); }]; //取消 UIAlertAction *canleAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { }]; //添加Action [alertController addAction:okAction]; [alertController addAction:canleAction]; //弹出 [self presentViewController:alertController animated:YES completion:nil];
相关文章推荐
- iOS开发 - UIAlertController 弹框提醒
- ios开发弹框提示(适配系统7,8,9)
- IOS 开发 View Controller 综述
- IOS开发 - 网络&数据库功能综述
- 【IOS 开发学习总结-OC-28】★objective-c之foundation 框架——集合类的综述
- iOS开发-轻松学会封装自定义视图view(自定义弹框封装详解)
- CJHUD 一种iOS开发中常用的弹框 An easy way to use HUD
- iOS蓝牙4.0开发02-Core Bluetooth框架综述
- iOS开发 - OC之UIAlertController 弹框提醒
- 手机游戏开发综述
- 浏览器端图形应用开发——使用基于XML的SVG[SVG综述]
- 2004开发技术年度综述之Java世界
- JAVA专题技术综述之线程篇-Java基础-Java-编程开发
- 软件开发方法综述
- 手机游戏开发综述
- 2004开发技术年度综述之Java世界
- 铁道中文应用开发现状综述
- 开工大吉!(我的第一篇CSDN日志,兼论我的第一次开发综述)
- 2004开发技术年度综述之移动开发
- 手机游戏开发综述