自定义动作控制器,Swift

时间:2016-02-19 11:20:13

标签: ios swift uialertcontroller

有没有人知道我如何编写这个自定义警报控制器(特别是顶部区域) - 目前在Apple音乐应用程序中找到。也许有一个已知的库可以做到这一点。

我知道你是如何对动作控制器进行编码的?

let alertController = UIAlertController(title: nil, message: "Top Message Here", preferredStyle: .ActionSheet)


        let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel) { (action) in
            // Drop View Pop up

        }

        alertController.addAction(cancelAction)

        let action1 = UIAlertAction(title: "Action Title", style: .Default) { (action) in

            //Code to Execute

        }

        alertController.addAction(action1)
        self.presentViewController(alertController, animated: true) {
            // ...

        }

enter image description here

2 个答案:

答案 0 :(得分:10)

以下是一个例子:

@IBAction func show() {
    let actionSheet = UIAlertController(title: "\n\n\n\n\n\n", message: nil, preferredStyle: .ActionSheet)

    let view = UIView(frame: CGRect(x: 8.0, y: 8.0, width: actionSheet.view.bounds.size.width - 8.0 * 4.5, height: 120.0))
    view.backgroundColor = UIColor.greenColor()
    actionSheet.view.addSubview(view)

    actionSheet.addAction(UIAlertAction(title: "Add to a Playlist", style: .Default, handler: nil))
    actionSheet.addAction(UIAlertAction(title: "Create Playlist", style: .Default, handler: nil))
    actionSheet.addAction(UIAlertAction(title: "Remove from this Playlist", style: .Default, handler: nil))

    actionSheet.addAction(UIAlertAction(title: "Cancel", style: .Cancel, handler: nil))
    presentViewController(actionSheet, animated: true, completion: nil)
}

答案 1 :(得分:2)

如果您偏离UIKit组件,我已为自定义操作表创建了library。它是用Swift编写的,允许您使用几种内置项类型创建自定义工作表。它也可以扩展和重新设计。