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选择框
前面介绍了两种文本输入框的用法,不过实际应用很少需要用户亲自文字,而是在界面上列出几个选项,让用户勾勾点点完成选择,这样既方便也不容易弄错.依据选择的唯一性,可将选项控件分为两类:一类是在方框中打勾的 ...
随机推荐
- Sony/索尼 NW-ZX300A ZX300 无损音乐播放器4.4口
https://item.taobao.com/item.htm?spm=a1z0d.7625083.1998302264.6.5c5f4e69ELHOcm&id=557859816402 ( ...
- 20145105 《Java程序设计》第9周学习总结
20145105 <Java程序设计>第9周学习总结 教材学习内容总结 第十六章 整合数据库 一.JDBC入门 (一)JDBC简介 厂商在操作JDBC驱动程序时,依操作方式可将驱动程序分为 ...
- 微信小程序——2、配置json文件
配置文件详解 主配置文件app.json 主配置文件位于主目录中,用于进行全局配置.包括页面文件的路径.窗口表现.设置网络超时时间.设置多tab等 下面通过微信最初自带小程序来学习 { "p ...
- String & dp Problem Round 3 2017.4.22
对每一个特征求前缀和,如果它减去前面的某一个地方的和,得到的每个特征是相等的,那么然后就可以更新答案. 需要解决这个两个问题 1.如何使答案尽量大? 这个很简单,直接找尽量靠前的地方就好了. 2,如何 ...
- C#调用托管ocx、dll
前篇文章是调用非托管,比较复杂,这里是调用托管,很简单[所以在遇到非托管dll时可以通过二次封装成托管的方式,再通过这边文章来使用] 1.注意这是基于COM的ocx或者dll,所以用regsvr32先 ...
- P4113 [HEOI2012]采花 (莫队TLE)
思路 update 11.2 树状数组AC 本题莫队过不去,会TLE ----------------------- 但也是个不错的莫队练手题 ------------------------ 毕竟C ...
- animate动画回调函数
对非动画的实现排队,比如这个css()是要放在回调函数里才能,让前面的动画执行完成后在进行实现 $('button').click(function(event) { $(this).next().a ...
- 【Coursera】SecondWeek(1)
全球互联网的始祖 APRANET APRANET 是 DARPA(美国国防部高级研究计划局) 开发的世界上第一个运营PacketSwitching(分包交换)的网络. 鉴于二战后世界格局两极化的历史背 ...
- 关于C++中的友元函数的总结
1.友元函数的简单介绍 1.1为什么要使用友元函数 在实现类之间数据共享时,减少系统开销,提高效率.如果类A中的函数要访问类B中的成员(例如:智能指针类的实现),那么类A中该函数要是类B的友元函数.具 ...
- C# ashx接收ContentType="text/xml"类型值
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain&qu ...