UIKit框架 - 06.UIActionSheet使用

来源:互联网 发布:2007-2017年的网络热词 编辑:程序博客网 时间:2024/06/15 17:33

1.UIAcitonSheet概述

  • 有时候我们希望提示框或弹窗能从底部弹出,苹果耶提供了这么一个类来实现这个功能
  • 功能显示
  • 这里写图片描述

2.代码实现

  • 这里我们实现基本功能,点击屏幕弹框出现,点击按钮,弹框消失
  • 弹框上设置了3个按钮
  • 注意:与UIAlertView类不同,UIAcitonSheet不能添加文本框
-(void)touchesBegan:(nonnull NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event{    // 1.创建UIActionSheet    UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"哥是标题" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"确认" otherButtonTitles:@"Other", nil];// 2.显示到视图上    [sheet showInView:self.view];}// 监听按钮点击事件// 只要UIActionSheet上的按钮被点击就会调用// actionSheet:谁触发事件就会把谁传递进来// clickedButtonAtIndex:当前被点击按钮的索引#pragma mark - UIActionSheetDelegate-(void)actionSheet:(nonnull UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{    // 0.确认按钮,Other是取消按钮,2是取消按钮    NSLog(@"%ld被点击了",buttonIndex);}

0 0