#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(选择框、操作表单)的更多相关文章

  1. android 弹出框(输入框和选择框)

    1.输入框: final EditText inputServer = new EditText(this); inputServer.setFilters(new InputFilter[]{new ...

  2. 使用elementUI的日期选择框,两选择框关联时间限值

    elementui 本身也提供了在一个输入框内关联选择时间的组件,非常好使,但无奈项目需要用两个输入框去关联的选择: <el-date-picker class="datepicker ...

  3. 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 ...

  4. 原生js实现一个自定义下拉单选选择框

    浏览器自带的原生下拉框不太美观,而且各个浏览器表现也不一致,UI一般给的下拉框也是和原生的下拉框差别比较大的,这就需要自己写一个基本功能的下拉菜单/下拉选择框了.最近,把项目中用到的下拉框组件重新封装 ...

  5. Java知多少(87)选择框和单选按钮(转)

    选择框.单选框和单选按钮都是选择组件,选择组件有两种状态,一种是选中(on),另一种是未选中(off),它们提供一种简单的 “on/off”选择功能,让用户在一组选择项目中作选择. 选择框 选择框(J ...

  6. IE8 下更改input[file] file文件选择框样式

    1/使用绝对定位,将文件选择框固定,并且隐藏该选择框(文件选择框可调整宽高),设置该文件选择框 z-index 调高 比如 999. 2/使用任意标签,调整为与上面选择框相同宽高,目的为使用该标签样式 ...

  7. Java知多少(87)选择框和单选按钮

    选择框.单选框和单选按钮都是选择组件,选择组件有两种状态,一种是选中(on),另一种是未选中(off),它们提供一种简单的 “on/off”选择功能,让用户在一组选择项目中作选择. 选择框 选择框(J ...

  8. Easyui datebox单击文本框显示日期选择

    Easyui默认是点击文本框后面的图标显示日期,为了更进一步优化体验 修改为单击文本框显示日期选择框 修改jquery.easyui.min.js(作者用的是1.3.6版本,其他版本或有区别) 可 c ...

  9. 十. 图形界面(GUI)设计8.选择框和单选按钮

    选择框.单选框和单选按钮都是选择组件,选择组件有两种状态,一种是选中(on),另一种是未选中(off),它们提供一种简单的 “on/off”选择功能,让用户在一组选择项目中作选择. 选择框 选择框(J ...

  10. Java开发笔记(一百二十二)AWT选择框

    前面介绍了两种文本输入框的用法,不过实际应用很少需要用户亲自文字,而是在界面上列出几个选项,让用户勾勾点点完成选择,这样既方便也不容易弄错.依据选择的唯一性,可将选项控件分为两类:一类是在方框中打勾的 ...

随机推荐

  1. P3008 [USACO11JAN]道路和飞机Roads and Planes

    P3008 [USACO11JAN]道路和飞机Roads and Planes Dijkstra+Tarjan 因为题目有特殊限制所以不用担心负权的问题 但是朴素的Dijkstra就算用堆优化,也显然 ...

  2. yum配合rpm查看软件包安装位置

    今天安装apache,新版本要求除了apache的安装包以外,还要求先安装apr.apr-util和pcre. 开始并没有急着去下载apr的安装包,而是想看看我的操作系统中有没有安装过了这个软件,结果 ...

  3. servlet+jsp+java实现Web应用

    servlet+jsp+java实现Web应用 环境: 1,eclipse 2,tomcat3,eclipse tomcat 插件 开发过程: 1,建立一个Dynamic Web Project 2, ...

  4. vc++之stdafx.h

    关于stdafx.h的解释,其实蛮多的,在vs中,既然创建c++工程的时候,默认会给生成main.cpp,并且自动包含了stdafx.h,而且stdafx.h不是c++标准的一部分,那么个人认为,理解 ...

  5. 20145333茹翔 Exp5 利用nmap扫描

    20145333茹翔 Exp5 利用nmap扫描 实验过程 首先使用命令创建一个msf所需的数据库 service postgresql start msfdb start 使用命令msfconsol ...

  6. 小K(wifi)插座剖解

    1.主控 AR9331 400MHZ MIPS 24k内核 2.flash:w9425G6JH-5 1352P 6316CF500ZY  RAM 32M

  7. C++ 项目中直接使用JsonCpp源码文件

    之前在网上看到使用JsonCpp都是以库的形式使用(编译源码为静态库或者动态库),这样引用很方便,但有时候报错调试看不到错误的地方,所以就想直接把源文件添加到项目中,方便调试 这是用到源码文件: 创建 ...

  8. The DELETE statement conflicted with the REFERENCE constraint

    Page是主表,主键是pageid:UserGroupPage表中的PageID字段是Page表里的数据. https://www.codeproject.com/Questions/677277/I ...

  9. 【基础知识】ActiveMQ基本原理

    “来,根据你的了解说下 ActiveMQ 是什么.” “这个简单,ActiveMQ 是一个 MOM,具体来说是一个实现了 JMS 规范的系统间远程通信的消息代理.它……” “等等,先解释下什么是 MO ...

  10. C#学习笔记(六):循环嵌套、复杂数据类型和枚举

    复杂数据类型 默认情况:0,1,2,3 赋值情况:0,3,4,5://修改初始值,后面都会改变 定义在class外面,作用域更大 定义在class里面(类种类),只能在类里使用 枚举作用:方便把不同角 ...