【问题标题】:Custom Action controller, Swift自定义动作控制器,Swift
【发布时间】:2016-05-31 22:52:14
【问题描述】:

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

        }

【问题讨论】:

标签: ios swift uialertcontroller


【解决方案1】:

如果您对偏离UIKit 组件感到满意,我已经为自定义操作表创建了library。它是用 Swift 编写的,可让您创建具有多种内置项目类型的自定义工作表。它也可以扩展和重新设置样式。

【讨论】:

    【解决方案2】:

    这是一个例子:

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

    【讨论】:

    • 如何改变标题的字体颜色?
    • actionSheet.view.tintColor = UIColor.red
    猜你喜欢
    • 1970-01-01
    • 2017-07-07
    • 2012-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-11
    • 2023-03-25
    相关资源
    最近更新 更多