我正在实现自定义警报,为背景设置颜色。下面的代码当我在模拟器中挤压时完美地工作,但是当我在iPhone上测试时,自定义背景被叠加在如下所示的模式中。Swift UIAlertController背景颜色
let alertController = UIAlertController(title: "Opções", message: "Deseja realmente excluir esse serviço?", preferredStyle: .Alert)
alertController.setValue(NSAttributedString(string: "Opções", attributes: [NSFontAttributeName : UIFont.systemFontOfSize(17),NSForegroundColorAttributeName : UIColor.whiteColor()]), forKey: "attributedTitle")
alertController.setValue(NSAttributedString(string: "Deseja realmente excluir esse serviço?", attributes: [NSFontAttributeName : UIFont.systemFontOfSize(17),NSForegroundColorAttributeName : UIColor.whiteColor()]), forKey: "attributedMessage")
alertController.view.tintColor = UIColor.whiteColor()
let backView = alertController.view.subviews.last?.subviews.last
backView?.layer.cornerRadius = 5.0
backView?.backgroundColor = corAzul
backView?.alpha = 1.0
let imageView = UIImageView(frame: CGRectMake(10, 15, 30, 30))
imageView.image = UIImage(named: "load")
alertController.view.addSubview(imageView)
let Action2 = UIAlertAction(title: "Excluir", style: .Default) { (action) in
Excluir()
}
let Action7 = UIAlertAction(title: "Cancelar", style: .Cancel) { (action) in
Cancelar()
}
alertController.addAction(Action2)
alertController.addAction(Action7)
viewController.presentViewController(alertController, animated: true) {}
这是什么原因?我该如何解决它?
在我看来,更好的是不要使用UIAlertController。制作你自己的类似警报的视图控制器很容易。 – matt
我在某些情况下完成了这项工作,但我的项目中有几个应用程序用于处理行动警报。我们很难做到完全可以配置的东西,并且可以替代任何 –
明白的项目。但是自定义UIAlertController视图不受支持,并且(如您所见)很脆弱。 – matt