IOS中UIActionSheet使用详解

IOS中UIActionSheet使用方法详解

1、初始化方法

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

 

参数说明:spa

title:视图标题.net

delegate:设置代理3d

cancelButtonTitle:取消按钮的标题代理

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

otherButtonTitles:其余按钮的标题索引

2、经常使用方法和属性介绍

 

@property(nonatomic,copy) NSString *title;get

设置标题it

 

@property(nonatomic) UIActionSheetStyle actionSheetStyle;io

设置风格,枚举以下:

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;

使用代码将视图收回

3、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;

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

专一技术,热爱生活,交流技术,也作朋友。

——珲少 QQ群:203317592

相关文章
相关标签/搜索