Swift开发 底部对话框UIActionSheet

来源:互联网 发布:淘宝虚拟物品货源 编辑:程序博客网 时间:2024/05/22 12:13
1.首先设置ActionSheet代理
2.实例一个ActionSheet
3.点击按钮的事件需要调用相应的方法才可以
4.按钮的编号从0开始,0是 destructiveButton  1是cancelButton  >=2 自定义按钮 使用 .addButtonWithTittle 添加

class ViewController:UIViewController, UIActionSheetDelegate


let actionSheet: UIActionSheet =UIActionSheet(title: "标题", delegate:self, cancelButtonTitle: "取消", destructiveButtonTitle:"红色按钮")

        

        //添加一个按钮

        actionSheet.addButtonWithTitle("按钮1")

        

        actionSheet.showInView(self.view)



func actionSheet(actionSheet: UIActionSheet, didDismissWithButtonIndex buttonIndex: Int) {

        

        switch buttonIndex {

            

        case 0:print("红色按钮")

        case 2:print("按钮1")

        default: print("取消")

        }

    }



0 0
原创粉丝点击