IOS中UIActionSheet使用详解

原文网址:http://my.oschina.net/u/2340880/blog/409907

摘要  IOS8后虽然出了新的控制器UIAlertController,但之前的UIAlertView,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,copyNSString *title;

设置标题

@property(nonatomicUIActionSheetStyle actionSheetStyle;

设置风格,枚举如下:

?
1
2
3
4
5
6
typedef  NS_ENUM(NSInteger, UIActionSheetStyle) {
     UIActionSheetStyleAutomatic        = -1,      
     UIActionSheetStyleDefault          = UIBarStyleDefault,
     UIActionSheetStyleBlackTranslucent = UIBarStyleBlackTranslucent,
     UIActionSheetStyleBlackOpaque      = UIBarStyleBlackOpaque,
};

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

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

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

获取按钮标题

@property(nonatomic,readonlyNSInteger numberOfButtons;

获取按钮数量

@property(nonatomicNSInteger cancelButtonIndex;

设置取消按钮的索引值

@property(nonatomicNSInteger 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;

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


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值