iOS界面编程-UIActionSheet

UIActionSheet

一、介绍

   UIActionSheet在ios8之后就被弃用了,在ios8及以后的版本中,推荐使用UIAlertController并指定preferredStyle为 UIAlertControllerStyleActionSheet.我们可以使用UIActionSheet去提醒用户去处理给定的任务,也可以使用动作列表去提醒用户去确认一个潜在的危险动作。动作列表包含选择的标题以及一个或者多个按钮,

二、相关属性及方法

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


@property(nullable,nonatomic,weak) id<UIActionSheetDelegate> delegate;

@property(nonatomic,copy) NSString *title;

@property(nonatomic) UIActionSheetStyle actionSheetStyle; // default is UIActionSheetStyleAutomatic. ignored if alert is visible

- (NSInteger)addButtonWithTitle:(nullable NSString *)title;    // returns index of button. 0 based.

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

@property(nonatomic,readonly) NSInteger numberOfButtons;

@property(nonatomic) NSInteger cancelButtonIndex;      // if the delegate does not implement -actionSheetCancel:, we pretend this button was clicked on. default is -1

@property(nonatomic) NSInteger destructiveButtonIndex;        // sets destructive (red) button. -1 means none set. default is -1. ignored if only one button

@property(nonatomic,readonly) NSInteger firstOtherButtonIndex; // -1 if no otherButtonTitles or initWithTitle:... not used

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


// show a sheet animated. you can specify either a toolbar, a tab bar, a bar button item or a plain view. We do a special animation if the sheet rises from

// a toolbar, tab bar or bar button item and we will automatically select the correct style based on the bar style. if not from a bar, we use

// UIActionSheetStyleDefault if automatic style set

- (void)showFromToolbar:(UIToolbar *)view;

- (void)showFromTabBar:(UITabBar *)view;

- (void)showFromBarButtonItem:(UIBarButtonItem *)item animated:(BOOL)animated NS_AVAILABLE_IOS(3_2);

- (void)showFromRect:(CGRect)rect inView:(UIView *)view animated:(BOOL)animated NS_AVAILABLE_IOS(3_2);

- (void)showInView:(UIView *)view;


// hides alert sheet or popup. use this method when you need to explicitly dismiss the alert.

// it does not need to be called if the user presses on a button

- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated;

三、实际例子


-(void)showActionButtonClicked:(id)sender{
  UIActionSheet *testAction =  [ [UIActionSheet alloc]initWithTitle:@"测试中" delegate:self cancelButtonTitle:@"cancle" destructiveButtonTitle:@"destructor" otherButtonTitles:@"sr", nil];
    [testAction showInView:self.view];
}





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

house.zhang

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值