提示框(警告框)控件2:UIActionSheet

功能:当点击按钮或标签等时,弹出一个提示框,显示必要的提示,然后通过添加的按钮完成需要的功能。它与导航栏类似,它继承自UIView。
 
风格类型:

typedef NS_ENUM(NSInteger, UIActionSheetStyle) {

UIActionSheetStyleAutomatic        = -1,       //iOS系统自动默认的风格

UIActionSheetStyleDefault          = UIBarStyleDefault,// 默认风格,灰色背景上显示白色文字

UIActionSheetStyleBlackTranslucent = UIBarStyleBlackTranslucent //透明黑色背景,白色文字

UIActionSheetStyleBlackOpaque      = UIBarStyleBlackOpaque,       //纯黑背景,白色文字

};

属性:

@property(nonatomic,assign) id<UIActionSheetDelegate> delegate;    // 代理

@property(nonatomic,copy) NSString *title;  //标题

@property(nonatomic) UIActionSheetStyle actionSheetStyle; //风格类型

@property(nonatomic,readonly) NSInteger numberOfButtons; //按钮数量

@property(nonatomic) NSInteger cancelButtonIndex;    //取消按钮的索引

@property(nonatomic) NSInteger destructiveButtonIndex;  //红色按钮索引

@property(nonatomic,readonly) NSInteger firstOtherButtonIndex; //其他第一个按钮索引

@property(nonatomic,readonly,getter=isVisible) BOOL visible; //是否可见

方法:

※创建实例的初始化方法

- (instancetype)initWithTitle:(NSString *)title delegate:(id<UIActionSheetDelegate>)delegate cancelButtonTitle:(NSString *)cancelButtonTitle destructiveButtonTitle:(NSString *)destructiveButtonTitle otherButtonTitles:(NSString *)otherButtonTitles, ...("Use UIAlertController instead.”);

※添加按钮,返回它的索引

- (NSInteger)addButtonWithTitle:(NSString *)title;

※返回指定索引的按钮文字

- (NSString *)buttonTitleAtIndex:(NSInteger)buttonIndex;

※显示在工具栏

- (void)showFromToolbar:(UIToolbar *)view;

※显示在导航栏

- (void)showFromTabBar:(UITabBar *)view;

※显示在工具栏按钮上

- (void)showFromBarButtonItem:(UIBarButtonItem *)item animated:(BOOL)animated ;

※在指定区域和视图上显示

- (void)showFromRect:(CGRect)rect inView:(UIView *)view animated:(BOOL)animated;

※在视图上显示

- (void)showInView:(UIView *)view;

※按钮消失

- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated;

代理方法:

@protocol UIActionSheetDelegate <NSObject>

@optional

//点击一个按钮时触发的方法

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex;

// 如果没有定义的委托,我们模拟一个点击取消按钮

- (void)actionSheetCancel:(UIActionSheet *)actionSheet;

//将要显示警告框时触发的方

- (void)willPresentActionSheet:(UIActionSheet *)actionSheet;

//已经显示提示框时触发的方法

- (void)didPresentActionSheet:(UIActionSheet *)actionSheet;

//提示框将要消失时触发的方法

- (void)actionSheet:(UIActionSheet *)actionSheet willDismissWithButtonIndex:(NSInteger)buttonIndex;

//提示框已经消失时触发的方法

- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex;

@end

举例如下:类实现协议

@interface ViewController ()<UIActionSheetDelegate>

1. //实例化

    //创建提示框实例
UIActionSheet *actionSheet = [[UIActionSheet alloc]initWithTitle:@"title" delegate:self cancelButtonTitle:@"cance" destructiveButtonTitle:@"destructive" otherButtonTitles:@"button1", @"button2",nil];

2. //设置风格

    //设置风格
actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;

3. //设置代理

    //设置代理
actionSheet.delegate = self;

4. //在视图上显示

    //在视图上显示
[actionSheet showInView:self.view];

实现代理方法:

#pragma mark-<UIActionSheetDelegate>

1.点击按钮时触发事件

//点击一个按钮时触发的方法
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLog(@"actionSheet: clickedButtonAtIndex:");
}

2.取消提示框时触发的事件

// 如果没有定义的委托,我们模拟一个点击取消按钮
- (void)actionSheetCancel:(UIActionSheet *)actionSheet
{
NSLog(@"actionSheetCancel:");
}

3.提示框将要显示时触发的事件

//将要显示警告框时触发的方
- (void)willPresentActionSheet:(UIActionSheet *)actionSheet
{
NSLog(@"willPresentActionSheet:");
}

4.显示提示框时触发的方法

//已经显示提示框时触发的方法
- (void)didPresentActionSheet:(UIActionSheet *)actionSheet
{
NSLog(@"didPresentActionSheet:");
}

5.提示框将要消失时触发的方法

//提示框将要消失时触发的方法
- (void)actionSheet:(UIActionSheet *)actionSheet willDismissWithButtonIndex:(NSInteger)buttonIndex
{
NSLog(@"actionSheet: willDismissWithButtonIndex:");
}

6.提示框消失时触发的方法

//提示框已经消失时触发的方法
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
{
NSLog(@"actionSheet: didDismissWithButtonIndex:");
}

演示结果如下:

代理方法调用情况如下:

程序运行起来, 没有点击按钮时:

-- ::29.647 提示框UIActionSheet[:] willPresentActionSheet:

点击任意按钮时:

-- ::18.882 提示框UIActionSheet[:] actionSheet: clickedButtonAtIndex:
-- ::18.883 提示框UIActionSheet[:] actionSheet: willDismissWithButtonIndex:
-- ::19.297 提示框UIActionSheet[:] actionSheet: didDismissWithButtonIndex:

iOS:提示框(警告框)控件UIActionSheet的详解的更多相关文章

  1. 《手把手教你》系列技巧篇(三十八)-java+ selenium自动化测试-日历时间控件-下篇(详解教程)

    1.简介 理想很丰满现实很骨感,在应用selenium实现web自动化时,经常会遇到处理日期控件点击问题,手工很简单,可以一个个点击日期控件选择需要的日期,但自动化执行过程中,完全复制手工这样的操作就 ...

  2. iOS:提示框(警告框)控件UIAlertView的详解

    提示框(警告框)控件:UIAlertView   功能:当点击按钮或标签等时,弹出一个提示框,显示必要的提示,然后通过添加的按钮完成需要的功能.   类型:typedef NS_ENUM(NSInte ...

  3. iOS:网页视图控件UIWebView的详解

    网页视图控件:UIWebView 功能:它是继承于UIView的,是一个内置的浏览器控件,以用来浏览从网络下载下来的网页或者本地上加载下来的文档. 枚举: //网页视图导航类型 typedef NS_ ...

  4. iOS:选择器控件UIPickerView的详解和演示

    选择器控件UIPickerView: 功能:它能够创建一个类似于密码锁式的单列或多列的选择菜单,用户可以通过它设置的代理来选择需要菜单中的任意的数据.例如创建日历.字体表(类型.大小.颜色).图库等. ...

  5. iOS:下拉刷新控件UIRefreshControl的详解

    下拉刷新控件:UIRefreshControl 1.具体类信息: @interface UIRefreshControl : UIControl //继承控制类 - (instancetype)ini ...

  6. iOS:图像选取器控制器控件UIImagePickerController的详解

    图像选择控制器:UIImagePickerController 功能:用于选取相册或相机等里面的照片. @interface UIImagePickerController : UINavigatio ...

  7. delphi控件属性大全-详解-简介

    http://blog.csdn.net/u011096030/article/details/18716713 button 组件: CAPTION 属性 :用于在按钮上显示文本内容 Cancel ...

  8. 【VB技巧】VB ListView 控件功能使用详解

    来源:http://lcx.cc/?i=494 ListView控件 在工具箱上击鼠标右键,选择快捷菜单的Components(部件)项,在控件列表中选择Microsoft Windows Commo ...

  9. 转 VB ListView控件各种操作详解

    Private Sub Form_Load() ListView1.ListItems.Clear '清空列表 ListView1.ColumnHeaders.Clear '清空列表头 ListVie ...

随机推荐

  1. HNOI 2014

    D1T1:画框 frame 题意:给你两个n阶正整数方阵,请你求最大的\( \sum_{i = 1}^{n} A_{i, p_i}\times \sum_{i = 1}^{n} B_{i, p_i}  ...

  2. jquery on方法(事件委托)

    jquery绑定事件处理函数的方法有好几个,比如:bind(),on(),delegate(),live(). 其中delegate和live都是用on实现的,效果也类似,live好像在1.7版本中已 ...

  3. Underscore.js-精巧而强大实用功能库

    前言 从其他语言转向Javascript时,通常都会遇到一些困惑性问题.比如,Java中的HashMap在Javascript中如何实现?Javascript面向对象式编程如何实现继承?如何实现通用的 ...

  4. 洛谷P2464 [SDOI2008] 郁闷的小j [分块]

    题目传送门 郁闷的小j 题目描述 小J是国家图书馆的一位图书管理员,他的工作是管理一个巨大的书架.虽然他很能吃苦耐劳,但是由于这个书架十分巨大,所以他的工作效率总是很低,以致他面临着被解雇的危险,这也 ...

  5. JAVA基础关键字小结一

    基础部分总是看起来简单,若要明白原理和使用场景,需要慢慢的体会. 本文对常用的关键字如final,transient,volatile,static以及foreach循环的原理重新梳理了一遍. 一.f ...

  6. HDU 1698 Just a Hook (线段树)

    Problem Description In the game of DotA, Pudge’s meat hook is actually the most horrible thing for m ...

  7. 【推导】zoj3981 Balloon Robot

    题意:一个桌子有m个位置(首尾相接),有n支队伍坐在其中的n个位置上.有个机器人会从某个起始位置出发,每个时刻会依次发生以下三个事件: 机器人顺时针转一个单位: 某些队伍通过了题目(如果存在): 如果 ...

  8. Shell基础学习(二) Shell变量

    1.数据类型: 字符串 数组 2.变量的命名规范: 只能以a-z或A-Z开头 中间不能有空格,可以使用_ 不能使用标点符号 不能使用shell的关键字 3.变量类型: 环境变量 局部变量 shell变 ...

  9. linux基础命令学习 (八)磁盘空间

    一.df linux中df命令的功能是用来检查linux服务器的文件系统的磁盘空间占用情况.于du不同的是,du是面向文件的命令,只计算被文件占用的空间.不计算文件系统metadata 占用的空间.d ...

  10. UVA 10972 RevolC FaeLoN(边-双连通+缩点)

    很好的一道图论题,整整撸了一上午... 题意是给定一个无向图,要求将所有边变为有向边,求最少加入多少条有向边,使得该图强连通?这里先假设一个问题:给定一个无向子图,该子图具有怎样的性质才能使得将其无向 ...