swift - UIAlertAction 背景颜色

标签 swift uialertcontroller

我的 UIAlertController 有问题,它没有正确显示背景颜色...你能帮我吗?

这是代码:

let alert = UIAlertController(title: "Choose qty", message: "", preferredStyle: UIAlertControllerStyle.alert)
let pickerController = PickerQtyController()
alert.setValue(pickerController, forKey: "contentViewController")
// Testing color
alert.view.tintColor=UIColor.blue
let backView = alert.view.subviews.last?.subviews.last
backView?.layer.cornerRadius = 10.0
backView?.backgroundColor = UIColor.blue
// Btns
let saveBtn = UIAlertAction(title: "Save", style: UIAlertActionStyle.default) {
    UIAlertAction in
    print("UIAlertController: Saved")
    pickerController.saveNewValueOfPicker()
}
let cancelBtn = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.cancel) {
    UIAlertAction in
    print("UIAlertController: Canceled")
}
alert.addAction(saveBtn)
alert.addAction(cancelBtn)
self.present(alert, animated: true)

谢谢!

最佳答案

这是丑陋且错误的设计。您应该创建一个自定义 View Controller 并将您的选择 Controller 添加到其中。将背景更改为透明并将模态呈现样式设置为覆盖当前上下文以显示自定义 View Controller 。

self.modalPresentationStyle = UIModalPresentationStyle.OverCurrentContext

关于swift - UIAlertAction 背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43174842/

相关文章:

swift - 在不使用 for 循环的情况下高效地在 iOS 中快速相交对象数组

ios - 插入耳机时奇怪的 AVMutableComposition 行为

ios - 无法将类型 'NSMutableArray' 的值转换为预期的参数类型 '[SKTexture]'

swift - Tableview reloadData() 不起作用

iOS 10 : UIAlertController only showing one action

macos - 将变量(颜色)传递给 NSView?

ios - iOS 上的高精度室内地理定位

ios - 是否可以向 UIAlertController 添加超链接?

ios - Swift 我无法隐藏分段控件

swift - 我所有的 UIAlertController 消息都变成了单行