繁体   English   中英

自定义动作控制器,Swift

[英]Custom Action controller, Swift

有谁知道我如何编写这个自定义警报控制器(特别是顶部区域) - 目前在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) {
            // ...

        }

在此输入图像描述

这是一个例子:

@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)
}

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM