你能说出这款带圆角的标准iPhone/Swift白色覆盖层吗?

Jos*_*Mum 1 iphone swift

我在许多应用程序[Twitter,在这种情况下]看到以下[popup/overlay]菜单,我想知道它是否是标准的Swift组件/库等等,如果有的话,如果有人知道我可能会在哪里请找,谢谢?JBM

从twitter应用程序弹出叠加菜单的屏幕截图

Dha*_*esh 5

作为Larme评论它是一个UIAlertControllerActionSheet风格.

考虑以下代码:

@IBAction func showActionSheet(sender: AnyObject) {
    // 1
    let optionMenu = UIAlertController(title: nil, message: "Choose Option", preferredStyle: .ActionSheet)

    // 2
    let deleteAction = UIAlertAction(title: "Delete", style: .Default, handler: {
        (alert: UIAlertAction!) -> Void in
        print("File Deleted")
    })
    let saveAction = UIAlertAction(title: "Save", style: .Default, handler: {
        (alert: UIAlertAction!) -> Void in
        print("File Saved")
    })

    //
    let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: {
        (alert: UIAlertAction!) -> Void in
        print("Cancelled")
    })


    // 4
    optionMenu.addAction(deleteAction)
    optionMenu.addAction(saveAction)
    optionMenu.addAction(cancelAction)

    // 5
    self.presentViewController(optionMenu, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)
  1. 创建一个具有ActionSheet样式的UIAlertController
  2. 创建了两个可以添加到警报控制器的操作.请注意在handler参数的括号内使用闭包
  3. 创建另一个动作,这次使用"取消"样式
  4. 操作将添加到警报控制器
  5. 提供警报控制器.

你的结果将是:

在此输入图像描述

您可以根据需要进行修改.

有关更多信息,请参阅教程.