最新消息:VPS服务器又从fzhost.net换回Linode了,主题仍用朋友推荐的大前端D8

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

Swift crifan 151浏览 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,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
18 queries in 0.253 seconds, using 9.93MB memory