UIActionSheet是弹出的按钮选项。
创建:
1.初始化:
- (instancetype)initWithTitle:(NSString *)title
delegate:(id<UIActionSheetDelegate>)delegate
cancelButtonTitle:(NSString *)cancelButtonTitle
destructiveButtonTitle:(NSString *)destructiveButtonTitle
otherButtonTitles:(NSString *)otherButtonTitles
title为弹出框的标题,delegate设置按钮被触摸时相应的委托类,cancelButtonTitle是取消按钮,destructiveButtonTitle是红色按钮,otherButtonTitles是你想设置的其他按钮,使用数组。
设置属性:
2.设置按钮被触摸时相应的委托代理类:
@property(nonatomic, assign) id< UIActionSheetDelegate > delegate
3.在标题栏显示的字符串:
@property(nonatomic, copy) NSString *title
4.是否显示:
@property(nonatomic, readonly, getter=isVisible) BOOL visible
5.显示风格:
@property(nonatomic) UIActionSheetStyle actionSheetStyle
typedef enum {
UIActionSheetStyleAutomatic = -1,
UIActionSheetStyleDefault = UIBarStyleDefault,
UIActionSheetStyleBlackTranslucent = UIBarStyleBlackTranslucent,
UIActionSheetStyleBlackOpaque = UIBarStyleBlackOpaque,
} UIActionSheetStyle;
配置按钮:
6.添加自定义按钮:
- (NSInteger)addButtonWithTitle:(NSString *)title
7.按钮数量:
@property(nonatomic, readonly) NSInteger numberOfButtons
8.根据索引,返回指定按钮的标题:
- (NSString *)buttonTitleAtIndex:(NSInteger)buttonIndex
9.取消按钮的索引:
@property(nonatomic) NSInteger cancelButtonIndex
10.红色高亮按钮的索引:
@property(nonatomic) NSInteger destructiveButtonIndex
11.第一个自定义按钮的索引:
@property(nonatomic, readonly) NSInteger firstOtherButtonIndex
呈现:
12.显示在标签条中:
- (void)showFromTabBar:(UITabBar *)view
13.显示在工具条中:
- (void)showFromToolbar:(UIToolbar *)view
14.显示在视图中:
- (void)showInView:(UIView *)view
15.在指定的按钮item显示:
- (void)showFromBarButtonItem:(UIBarButtonItem *)item
animated:(BOOL)animated
16.显示在指定视图:
- (void)showFromRect:(CGRect)rect
inView:(UIView *)view
animated:(BOOL)animated
解除:
17.立即解除(隐藏):
- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex
animated:(BOOL)animated
UIActionSheetDelegate:
应对措施:
1.触摸操作表中的任意按钮是触发:
- (void)actionSheet:(UIActionSheet *)actionSheet
clickedButtonAtIndex:(NSInteger)buttonIndex
此方法比4先调用。
定制行为:
2.操作表显示前被调用:
- (void)willPresentActionSheet:(UIActionSheet *)actionSheet
3.操作表显示后被调用:
- (void)didPresentActionSheet:(UIActionSheet *)actionSheet
4.操作表被关闭前调用:
- (void)actionSheet:(UIActionSheet *)actionSheet
willDismissWithButtonIndex:(NSInteger)buttonIndex
5.操作表关闭后被调用:
- (void)actionSheet:(UIActionSheet *)actionSheet
didDismissWithButtonIndex:(NSInteger)buttonIndex
操作表显示中应用程序进入睡眠状态也会被调用。取消:
6.取消:
- (void)actionSheetCancel:(UIActionSheet *)actionSheet