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选择框
前面介绍了两种文本输入框的用法,不过实际应用很少需要用户亲自文字,而是在界面上列出几个选项,让用户勾勾点点完成选择,这样既方便也不容易弄错.依据选择的唯一性,可将选项控件分为两类:一类是在方框中打勾的 ...
随机推荐
- shell中参数及带色彩打印
shell脚本中的一些函数参数说明如下: #!/bin/bash echo 显示参数的个数: $# echo 以单个字符串把每个参数连接起来: $* echo 显示脚本当前运行的进程id: $$ ec ...
- 20145221《网络对抗》PC平台逆向破解
20145221<网络对抗>PC平台逆向破解 实践目标 本次实践的对象是一个名为pwn1的linux可执行文件. 该程序正常执行流程是:main调用foo函数,foo函数会简单回显任何用户 ...
- git分支 远程协作
创建文件mkdir ### cd ### git init 初始化 git config global user.name “username” git config global user.emia ...
- C# string字节数组转换
string转byte[]:byte[] byteArray = System.Text.Encoding.Default.GetBytes ( str ); byte[]转string:string ...
- Python3基础 file for+文件指针 读取txt文本并 一行一行的输出(高效率)
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- Github使用教程详解
官方网站:http://git-scm.com Git是目前世界上最先进的分布式版本控制系统(没有之一). Git有什么特点?简单来说就是:高端大气上档次! 一.Git安装 在Linux上安装Git ...
- HDU 2204 Eddy's爱好(容斥原理dfs写法)题解
题意:定义如果一个数能表示为M^k,那么这个数是好数,问你1~n有几个好数. 思路:如果k是合数,显然会有重复,比如a^(b*c) == (a^b)^c,那么我们打个素数表,指数只枚举素数,2^60 ...
- 卸载vs2017
卸载enterprise版本 Microsoft.FSharp.SDK.Core卸载失败Package 'Microsoft.FSharp.SDK.Core,version=15.7.20180605 ...
- BZOJ3296: [USACO2011 Open] Learning Languages 并查集
Description 农夫约翰的N(2 <= N<=10,000)头奶牛,编号为1.. N,一共会流利地使用M(1<= M <=30,000)种语言,编号从1 .. M., ...
- 有关keras(Ubuntu14.04,python2.7)
第一部分:安装 由于我的电脑之前已经已经配置好了caffe,因此有关python的一切相关包都已经安装完成.因此,即使不用Anaconda安装依然很简单. sudo pip install tenso ...