swift中UIActionSheet的使用


[objc] view plain copy
  1. //方法1
  2. letalertSheet=UIActionSheet(title:alertTitle,delegate:nil,cancelButtonTitle:alertOK,0);background-color:inherit;">destructiveButtonTitle:alertCancel)
  3. alertSheet.showInView(self.view)


//方法2
  • //实例化时添加代理对象,同时注意添加协议
  • letalertSheet=UIActionSheet(title:alertTitle,153);background-color:inherit;font-weight:bold;">self,0);background-color:inherit;">destructiveButtonTitle:alertCancel,0);background-color:inherit;">otherButtonTitles:"警告","提示","通告")
  • alertSheet.showInView(self.view)
  • //添加协议
  • classViewController:UIViewController,UIActionSheetDelegate{
  • overridefuncviewDidLoad(){
  • ...
  • }
  • }
  • //代理方法
  • //MARK:UIActionSheetDelegate
  • funcactionSheet(actionSheet:UIActionSheet,clickedButtonAtIndexbuttonIndex:Int){
  • letbuttonTitle=actionSheet.buttonTitleAtIndex(buttonIndex)
  • ifbuttonTitle==alertCancel
  • {
  • print("你点击了退出")
  • elseifbuttonTitle==alertOK
  • print("你点击了确定")
  • else
  • print("你点击了其他")
  • }
  • //方法3
  • //1实例化
  • letalertSheet=UIAlertController(title:alertTitle,0);background-color:inherit;">message:alertMessage,0);background-color:inherit;">preferredStyle:UIAlertControllerStyle.ActionSheet)
  • //2命令(样式:退出Cancel,警告Destructive-按钮标题为红色,认Default)
  • letcancelAction=UIAlertAction(title:alertCancel,0);background-color:inherit;">style:UIAlertActionStyle.Cancel,0);background-color:inherit;">handler:nil)
  • letdeleteAction=UIAlertAction(title:"删除",0);background-color:inherit;">style:UIAlertActionStyle.Destructive,153);background-color:inherit;font-weight:bold;">nil)
  • letarchiveAction=UIAlertAction(title:alertOK,0);background-color:inherit;">style:UIAlertActionStyle.Default,0);background-color:inherit;">handler:{
  • actionin
  • print("OK")
  • })
  • alertSheet.addAction(cancelAction)
  • alertSheet.addAction(deleteAction)
  • alertSheet.addAction(archiveAction)
  • //3跳转
  • self.presentViewController(alertSheet,0);background-color:inherit;">animated:true,0);background-color:inherit;">completion:nil)
  • 相关文章

    软件简介:蓝湖辅助工具,减少移动端开发中控件属性的复制和粘...
    现实生活中,我们听到的声音都是时间连续的,我们称为这种信...
    前言最近在B站上看到一个漂亮的仙女姐姐跳舞视频,循环看了亿...
    【Android App】实战项目之仿抖音的短视频分享App(附源码和...
    前言这一篇博客应该是我花时间最多的一次了,从2022年1月底至...
    因为我既对接过session、cookie,也对接过JWT,今年因为工作...