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

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 14,678评论 4 61
  • 叶子层层的透出一点点的缝隙,毒辣的阳光便趁机而入。手心里捏着的伞也抵不住这般火热,骨子里多余的垃圾都化成水被太阳勾...
    别清欢阅读 2,732评论 0 2
  • 走吧,让我们一起回到起点 携手来到故事的开场 自私而又轻狂 任凭风声消失在海里 安排一次崭新的日出 就我和你,等待...
    柳小七阅读 1,823评论 0 0
  • 为什么你过的不尽兴,为什么你活的一点都不痛快?这个问题你应该比我思考过更多次吧。因为你家没钱,因为你爹不是李刚,因...
    小耳东阅读 2,773评论 0 0
  • 一、序言 1.不得不交代的背景——无意和潜水 认识顾老师纯属偶然。2016年4月,顾老师作为陈旎老师的助教到我们...
    奥利瓦_5f1c阅读 4,464评论 4 0

友情链接更多精彩内容