您的位置:首页 > 产品设计 > UI/UE

UIKit框架 - 06.UIActionSheet使用

2015-07-13 21:50 483 查看

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);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: