UIActionSheet简介

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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值