IOS中UIActionSheet使用详解

简介: IOS中UIActionSheet使用详解

IOS中UIActionSheet使用方法详解

一、初始化方法

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

 

参数说明:

title:视图标题

delegate:设置代理

cancelButtonTitle:取消按钮的标题

destructiveButtonTitle:特殊标记的按钮的标题

otherButtonTitles:其他按钮的标题

二、常用方法和属性介绍

 

@property(nonatomic,copy) NSString *title;

设置标题

 

@property(nonatomic) UIActionSheetStyle actionSheetStyle;

设置风格,枚举如下:

typedef NS_ENUM(NSInteger, UIActionSheetStyle) {
    UIActionSheetStyleAutomatic        = -1,      
    UIActionSheetStyleDefault          = UIBarStyleDefault,
    UIActionSheetStyleBlackTranslucent = UIBarStyleBlackTranslucent,
    UIActionSheetStyleBlackOpaque      = UIBarStyleBlackOpaque,
};

 

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

添加一个按钮,会返回按钮的索引

 

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

获取按钮标题

 

@property(nonatomic,readonly) NSInteger numberOfButtons;

获取按钮数量

@property(nonatomic) NSInteger cancelButtonIndex;

设置取消按钮的索引值

 

@property(nonatomic) NSInteger destructiveButtonIndex;

设置特殊标记

 

@property(nonatomic,readonly,getter=isVisible) BOOL visible;

视图当前是否可见

 

下面是几种弹出方式,会根据风格不同展现不同的方式

- (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;

使用代码将视图收回

三、UIActionSheet代理方法

 

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

点击按钮时触发的方法

 

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

视图将要弹出时触发的方法

 

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

视图已经弹出式触发的方法

 

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

点击按钮后,视图将要收回时触发的方法

 

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

点击按钮后,视图已经收回时触发的方法

目录
相关文章
|
iOS开发 Swift 索引
iOS - UIActionSheet
前言 NS_CLASS_DEPRECATED_IOS(2_0, 8_3, "UIActionSheet is deprecated. Use UIAlertController with a preferredStyle of UIAlertControllerStyleA...
852 0
|
Android开发 iOS开发
iOS 8 引入的 UIActionSheet 和 UIAlertView 的替代品 - UIAlertController
iOS 8 引入的 UIActionSheet 的替代品 - UIAlertController 太阳火神的美丽人生 (http://blog.csdn.net/opengl_es) 本文遵循“署名-非商业用途-保持一致”创作公用协议 转载请保留此句:太阳火神的美丽人生 -  本博客专注于 敏捷开发及移动和物联设备研究:iOS、Android、Html5、Arduino、pcDuino,否则,出自本博客的文章拒绝转载或再转载,谢谢合作。
1110 0
|
Android开发 iOS开发 HTML5
iOS 8 中 UIAlertView 和 UIActionSheet 河里去了?
iOS 8 中 UIAlertView 和 UIActionSheet 河里去了? 太阳火神的美丽人生 (http://blog.csdn.net/opengl_es) 本文遵循“署名-非商业用途-保持一致”创作公用协议 转载请保留此句:太阳火神的美丽人生 -  本博客专注于 敏捷开发及移动和物联设备研究:iOS、Android、Html5、Arduino、pcDuino,否则,出自本博客的文章拒绝转载或再转载,谢谢合作。
1182 0
|
iOS开发 C++
iOS学习之UIActionSheet的使用
UIActionSheet是在iOS弹出的选择按钮项,可以添加多项,并为每项添加点击事件。 为了快速完成这例子,我们打开Xcode 4.3.2, 先建立一个single view application。
801 0
|
1月前
|
API 数据安全/隐私保护 iOS开发
利用uni-app 开发的iOS app 发布到App Store全流程
利用uni-app 开发的iOS app 发布到App Store全流程
92 3
|
3月前
|
存储 iOS开发
iOS 开发,如何进行应用的本地化(Localization)?
iOS 开发,如何进行应用的本地化(Localization)?
122 2
|
3月前
|
存储 数据建模 数据库
IOS开发数据存储:什么是 UserDefaults?有哪些替代方案?
IOS开发数据存储:什么是 UserDefaults?有哪些替代方案?
40 0