iOS UI-AlertView(警示框)和ActionSheet(选择框、操作表单)
#import "ViewController.h" @interface ViewController ()<UIAlertViewDelegate,UIActionSheetDelegate> @end @implementation ViewController #pragma mark - 生命周期
- (void)viewDidLoad {
[super viewDidLoad];
// 创建展示AlertView的按钮
UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
[btn setTitle:@"AlertView" forState:UIControlStateNormal];
[btn setFrame:CGRectMake(, , , )];
//btn.center =self.view.center;
[btn setBackgroundColor:[UIColor orangeColor]];
[btn addTarget:self action:@selector(showAlert) forControlEvents:UIControlEventTouchUpInside]; // 创建展示ActionSheet的按钮
[self.view addSubview:btn];
UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeSystem];
[btn1 setTitle:@"ActionSheet" forState:UIControlStateNormal];
[btn1 setFrame:CGRectMake(, , , )];
[btn1 setBackgroundColor:[UIColor redColor]];
[btn1 addTarget:self action:@selector(showActionSheet) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn1]; }
#pragma mark - 关联事件 #pragma mark - 警示框
- (void)showAlert
{
/* UIAlertView警示框控件
注意
不用创建全局的Alert
尽量不要关联逻辑操作,如果关联实现协议:UIAlertViewDelegate以及里面的协议方法 */
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"错误"
message:@"网络连接失败"
delegate:self
cancelButtonTitle:@"好的"
otherButtonTitles:@"方案1",@"方案2",@"方案3", nil]; [alert show];
}
#pragma mark - 选择框
- (void)showActionSheet
{
/* UIActionSheet 选择框
注意
不用创建全局的UIActionSheet
尽量关联逻辑操作,如果关联实现协议:UIActionSheetDelegate以及里面的协议方法 */ UIActionSheet *action = [[UIActionSheet alloc] initWithTitle:@"请选择你的节操充值额度"
delegate:self
cancelButtonTitle:@"算了,不要了"
destructiveButtonTitle:@"18.00RMB"
otherButtonTitles:@"19.00RMB",@"20.00RMB",@"21.00RMB", nil]; [action showInView:self.view];
} #pragma mark - 选择框代理方法
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
switch (buttonIndex) {
case :
NSLog(@"第一种情况");
break;
case :
NSLog(@"第二种情况");
break;
case :
NSLog(@"第三种情况");
break;
case :
NSLog(@"第四种情况");
break;
case :
NSLog(@"第五种情况");
break; default:
break;
}
}
#pragma mark - 警示框代理方法
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
switch (buttonIndex) {
case :
NSLog(@"序号为0");
break;
case :
NSLog(@"序号为1");
break;
case :
NSLog(@"序号为2");
break;
case :
NSLog(@"序号为3");
break; default:
break;
}
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end
//
// ViewController.m
// IOS_0226_UIAlertController
//
// Created by ma c on 16/2/26.
// Copyright © 2016年 博文科技. All rights reserved.
// #import "ViewController.h" @interface ViewController ()
@property (weak, nonatomic) IBOutlet UIButton *btnClick; @end @implementation ViewController /*
UIPresentationController ->管理所有Modal出来的控制器 1.管理所有通过presentViewController方法显示出来的控制器
2.只要调用了presentViewController方法就会创建UIPresentationController
3.管理/监听切换控制器的过程
4.属性
//当前控制器
@property(nonatomic, strong, readonly) UIViewController *presentingViewController;
//切换的控制器
@property(nonatomic, strong, readonly) UIViewController *presentedViewController;
//切换的控制器视图
- (nullable UIView *)presentedView; 5.UIViewController属性 @property (nonatomic,readonly) UIPresentationController *presentationController
@property (nonatomic,readonly) UIPopoverPresentationController *popoverPresentationController 这两个属性指向UIPresentationController */ - (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor cyanColor]; } - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
//[self createAlertVC];
[self createPopoverPresentationVC];
} - (void)createAlertVC
{
//警示框
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"好久不见,你又不乖了。" preferredStyle:UIAlertControllerStyleAlert];
//添加按钮
UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"点击了确定按钮");
}]; [alert addAction:action]; [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"点击了取消按钮");
}]]; //添加文本框
[alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
textField.borderStyle = UITextBorderStyleRoundedRect;
textField.textColor = [UIColor redColor];
textField.text = @"";
[textField addTarget:self action:@selector(uernameChange:) forControlEvents:UIControlEventEditingChanged]; }];
[alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
textField.borderStyle = UITextBorderStyleRoundedRect; textField.secureTextEntry = YES;
textField.text = @"";
}];
[self presentViewController:alert animated:nil completion:nil];
} - (void)uernameChange:(UITextField *)textField
{
NSLog(@"%@",textField.text);
} - (void)createPopoverPresentationVC
{
UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:@"提示" message:@"请选择操作" preferredStyle:UIAlertControllerStyleActionSheet];
//设置展示形式
actionSheet.modalTransitionStyle = UIModalPresentationPopover;
self.popoverPresentationController.sourceView = self.btnClick;
self.popoverPresentationController.sourceRect = self.btnClick.bounds; UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"点击了确定按钮");
}];
[actionSheet addAction:action]; [actionSheet addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"点击了取消按钮");
}]]; [self presentViewController:actionSheet animated:nil completion:nil]; } @end
iOS UI-AlertView(警示框)和ActionSheet(选择框、操作表单)的更多相关文章
- android 弹出框(输入框和选择框)
1.输入框: final EditText inputServer = new EditText(this); inputServer.setFilters(new InputFilter[]{new ...
- 使用elementUI的日期选择框,两选择框关联时间限值
elementui 本身也提供了在一个输入框内关联选择时间的组件,非常好使,但无奈项目需要用两个输入框去关联的选择: <el-date-picker class="datepicker ...
- Swift - 选择框(UIPickerView)的用法
1,选择框可以让用户以滑动的方式选择值.示例如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 ...
- 原生js实现一个自定义下拉单选选择框
浏览器自带的原生下拉框不太美观,而且各个浏览器表现也不一致,UI一般给的下拉框也是和原生的下拉框差别比较大的,这就需要自己写一个基本功能的下拉菜单/下拉选择框了.最近,把项目中用到的下拉框组件重新封装 ...
- Java知多少(87)选择框和单选按钮(转)
选择框.单选框和单选按钮都是选择组件,选择组件有两种状态,一种是选中(on),另一种是未选中(off),它们提供一种简单的 “on/off”选择功能,让用户在一组选择项目中作选择. 选择框 选择框(J ...
- IE8 下更改input[file] file文件选择框样式
1/使用绝对定位,将文件选择框固定,并且隐藏该选择框(文件选择框可调整宽高),设置该文件选择框 z-index 调高 比如 999. 2/使用任意标签,调整为与上面选择框相同宽高,目的为使用该标签样式 ...
- Java知多少(87)选择框和单选按钮
选择框.单选框和单选按钮都是选择组件,选择组件有两种状态,一种是选中(on),另一种是未选中(off),它们提供一种简单的 “on/off”选择功能,让用户在一组选择项目中作选择. 选择框 选择框(J ...
- Easyui datebox单击文本框显示日期选择
Easyui默认是点击文本框后面的图标显示日期,为了更进一步优化体验 修改为单击文本框显示日期选择框 修改jquery.easyui.min.js(作者用的是1.3.6版本,其他版本或有区别) 可 c ...
- 十. 图形界面(GUI)设计8.选择框和单选按钮
选择框.单选框和单选按钮都是选择组件,选择组件有两种状态,一种是选中(on),另一种是未选中(off),它们提供一种简单的 “on/off”选择功能,让用户在一组选择项目中作选择. 选择框 选择框(J ...
- Java开发笔记(一百二十二)AWT选择框
前面介绍了两种文本输入框的用法,不过实际应用很少需要用户亲自文字,而是在界面上列出几个选项,让用户勾勾点点完成选择,这样既方便也不容易弄错.依据选择的唯一性,可将选项控件分为两类:一类是在方框中打勾的 ...
随机推荐
- HTML切换页面IE版本
<!--[if !IE]><!--> 除IE外都可识别 <!--<![endif]--><!--[if IE]> 所有的IE可识别 <![e ...
- Python3基础 raise 产生RuntimeError 异常
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- linux交叉编译gcc4.8.3
1.环境: Ubuntu 16.04 2.获取 wget mirrors.ustc.edu.cn/gnu/gcc/gcc-4.8.3/gcc-4.8.3.tar.bz2 3.解压 tar xvf gc ...
- P4879 ycz的妹子
思路 让你干啥你就干啥呗 查询第x个妹子就get一下再修改 这里稳一点就维护了三个东西,也许两个也可以 代码 #include <iostream> #include <cstdio ...
- 通过java代码对kylin进行cube build
转:http://www.cnblogs.com/hark0623/p/5580632.html 通常是用于增量 代码如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 ...
- HDU 5963 朋友(找规律博弈)
http://acm.hdu.edu.cn/showproblem.php?pid=5963 题意: 思路: 我们可以先只考虑单链,自己试几种案例就可以发现规律,只有与根相连的边为1时,只需要奇数次操 ...
- 51nod 1412 AVL树的种类(经典dp)
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1412 题意: 思路: 经典dp!!!可惜我想不到!! $dp[i][k] ...
- UVa 1602 网格动物(回溯)
https://vjudge.net/problem/UVA-1602 题意:计算n连通块不同形态的个数. 思路: 实在是不知道该怎么做好,感觉判重实在是太麻烦了. 判重就是判断所有格子位置是否都相同 ...
- hibernate报错 java.lang.StackOverflowError: null
在使用hibernate时,报错 java.lang.StackOverflowError: null 把当前线程的栈打满了 java.lang.StackOverflowError: null at ...
- java编程内容之开始
java应用程序开发应该掌握的各方面技术 1.初识java,熟悉Eclipse开发工具 2.java语言基础 3.流程控制,数组,字符串,类与对象 4.接口,继承与多态,类的高级特性 5.Java集合 ...