上拉菜单html,iOS开发之提示框与上拉菜单

提示框是做项目时候经常遇到的一个功能,可以提高用户体验,除了一些著名的第三方库以外,我们更多会用到系统提供的提示框和上拉菜单。这里总结UIAlertView、UIActionSheet、UIAlertController的一些基础用法。

iOS8之前用的是UIAlertView、UIActionSheet,在iOS8之后UIAlertController就取代了前面两个。

UIAlertView

这个方法通过设置一个标题,内容和些按钮创建提示框,代码示例如下:

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"网络请求失败" message:@"请检查网络设置" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];

[alert show];

UIActionSheet

UIActionSheet *actionSheet = [[UIActionSheet alloc]initWithTitle:@"title" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"确定" otherButtonTitles:@"第一项",@"第二项", nil];

//设置样式

actionSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;

[actionSheet showInView:self.view];

UIAlertController

UIAlertController包含了UIActionSheet, UIAlertView的功能

提示框的功能,代码示例:

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"标题" message:@"这个是UIAlertController的默认样式" preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];

UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"好的" style:UIAlertActionStyleDefault handler:nil];

[alertController addAction:cancelAction];

[alertController addAction:okAction];

[self presentViewController:alertController animated:YES completion:nil];

上拉菜单的功能,代码示例:

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"title" message:@"删除数据将不可恢复" preferredStyle: UIAlertControllerStyleActionSheet];

UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];

UIAlertAction *deleteAction = [UIAlertAction actionWithTitle:@"删除" style:UIAlertActionStyleDestructive handler:nil];

UIAlertAction *archiveAction = [UIAlertAction actionWithTitle:@"保存" style:UIAlertActionStyleDefault handler:nil];

[alertController addAction:cancelAction];

[alertController addAction:deleteAction];

[alertController addAction:archiveAction];

[self presentViewController:alertController animated:YES completion:nil];

如果对你有帮助,那就点个赞吧~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值