最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

[已解决]swift实现选择对话框

Swift crifan 2611浏览 0评论

要实现这种:

swift popup dialog

cocoa touch – How would I create a UIAlertView in Swift? – Stack Overflow

swift UIAlertAction example

ios – How do I code an UIAlertAction in Swift? – Stack Overflow

Programming-iOS-Book-Examples/ViewController.swift at master · mattneub/Programming-iOS-Book-Examples · GitHub

代码:

            let quitAlertController = UIAlertController(title: "确认", message: "确认要退出吗?", preferredStyle: UIAlertControllerStyle.Alert)
            let cancelAlertAction = UIAlertAction(title: "取消", style: UIAlertActionStyle.Cancel, handler: nil)
            quitAlertController.addAction(cancelAlertAction)
            let sureAlertAction = UIAlertAction(title: "确定", style: UIAlertActionStyle.Default, handler: doQuitHandler)
            quitAlertController.addAction(sureAlertAction)
            self.presentViewController(quitAlertController, animated: true, completion: nil)
    func doQuitHandler(alerAction:UIAlertAction){
        print("doQuitHandler: alerAction=\(alerAction)")
        //doQuitHandler: alerAction=<UIAlertAction: 0x7f8c23a5d4a0 Title = "确定" Descriptive = "(null)" Image = 0x0>
    }

效果:

把“确定”从

UIAlertActionStyle.Default

换成

UIAlertActionStyle.Destructive

let sureAlertAction = UIAlertAction(title: "确定", style: UIAlertActionStyle.Destructive, handler: doQuitHandler)

效果是红色字体:

转载请注明:在路上 » [已解决]swift实现选择对话框

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
84 queries in 0.164 seconds, using 22.08MB memory