#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. margin显示怪异,外边距合并问题

    很多时候我们使用两个div,内层的div设置文字,需要垂直居中与上层div,但是怎么设置样式都不行,vertical-align:middle也不行. 代码: <div style=" ...

  2. 20145301赵嘉鑫《网络对抗》Exp8 Web基础

    20145301赵嘉鑫<网络对抗>Exp8 Web基础 基础问题回答 什么是表单? 表单是一个包含表单元素的区域,主要负责数据采集部分.表单元素允许用户在表单中输入信息.一个表单有三个基本 ...

  3. 20145315何佳蕾《网络对抗》MSF基础应用

    20145315何佳蕾<网络对抗>MSF基础应用 实验过程记录 (1)一个主动攻击,ms08_067; 1.打开msfconsole 2.use exploit/windows/smb/m ...

  4. CP2102

    1概述 CP2102其集成度高,内置USB2.0全速功能控制器.USB收发器.晶体振荡器.EEPROM及异步串行数据总线(UART),支持调制解调器全功能信号,无需任何外部的USB器件.CP2102与 ...

  5. VC++ 进度条更新方案

    在实际开发中,如果有耗时操作,一般会在工作线程处理数据,然后处理完成后把时间传递到UI线程进行显示,切记不要在工作线程对UI进行操作. 场景: 1. 很多程序需要根据处理业务的进度来更新进度条,进度条 ...

  6. MySQL 5.7.18 解压版安装

    原文链接:https://my.oschina.net/u/3474266/blog/895696 我在安装免安装版的5.7.18的时候出现了问题,正好找到这个,十分感激 今天下载安装了MySQL C ...

  7. [luogu 2458][SDOI2006]保安站岗

    题目描述 五一来临,某地下超市为了便于疏通和指挥密集的人员和车辆,以免造成超市内的混乱和拥挤,准备临时从外单位调用部分保安来维持交通秩序. 已知整个地下超市的所有通道呈一棵树的形状:某些通道之间可以互 ...

  8. java中年月日的加减法,年月的加减法使用

    本文为博主原创,未经允许不得转载: java计算两个年月日之间相差的天数: public static int daysBetween(String smdate,String bdate) thro ...

  9. js访3d上下轮播图

    js/css访3d上下轮播图 (附件) <!DOCTYPE html> <html> <head> <meta charset="utf-8&quo ...

  10. bind9安装配置

    BIND的安装配置: dns服务,程序包名叫bind,程序名named 程序包: bind bind-libs bind-utils bind-chroot: /var/named/chroot/ b ...