我的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)
谢谢!
答案 0 :(得分:1)
这是丑陋和错误的设计。您应该创建一个自定义视图控制器并将拾取控制器添加到其中。将背景更改为透明并将模式演示文稿样式设置为当前上下文以显示自定义视图控制器。
self.modalPresentationStyle = UIModalPresentationStyle.OverCurrentContext