如何将黑色背景颜色设置为警报?
How to set a black background color to an alert?
我目前正在开发 iOS 应用程序。
我已自定义提醒以匹配我的应用程序的颜色。
这是代码:
func createPopUp(title: String, message: String, preferredStyle: UIAlertController.Style) -> UIAlertController {
let alert = UIAlertController(title: title, message: message, preferredStyle: preferredStyle)
alert.setTitlet(font: UIFont.boldSystemFont(ofSize: 17), color: UIColor.customOrange)
alert.setMessage(font: UIFont.systemFont(ofSize: 13), color: UIColor.customOrange)
let subview = alert.view.subviews.first! as UIView
let alertContentView = subview.subviews.first! as UIView
alertContentView.backgroundColor = UIColor.black // This is the important line
alertContentView.tintColor = UIColor.customOrange
alertContentView.layer.cornerRadius = 15;
return alert
}
只有当我启动应用程序时,我才会得到这个渲染:
RenderingBlack
背景颜色不是黑色。但是,当我更改 UIColor 时,例如:
alertContentView.backgroundColor = UIColor.green
渲染正确:
RenderingGreen
尽管在网上进行了研究,但我找不到解决方案。
感谢您的宝贵时间:)
你好恶魔请更换
alertContentView.backgroundColor = UIColor.black
alert.view.subviews.first?.subviews.first?.subviews.first?.backgroundColor = .black
它将解决您的问题。
我目前正在开发 iOS 应用程序。 我已自定义提醒以匹配我的应用程序的颜色。 这是代码:
func createPopUp(title: String, message: String, preferredStyle: UIAlertController.Style) -> UIAlertController {
let alert = UIAlertController(title: title, message: message, preferredStyle: preferredStyle)
alert.setTitlet(font: UIFont.boldSystemFont(ofSize: 17), color: UIColor.customOrange)
alert.setMessage(font: UIFont.systemFont(ofSize: 13), color: UIColor.customOrange)
let subview = alert.view.subviews.first! as UIView
let alertContentView = subview.subviews.first! as UIView
alertContentView.backgroundColor = UIColor.black // This is the important line
alertContentView.tintColor = UIColor.customOrange
alertContentView.layer.cornerRadius = 15;
return alert
}
只有当我启动应用程序时,我才会得到这个渲染:
RenderingBlack
背景颜色不是黑色。但是,当我更改 UIColor 时,例如:
alertContentView.backgroundColor = UIColor.green
渲染正确:
RenderingGreen
尽管在网上进行了研究,但我找不到解决方案。
感谢您的宝贵时间:)
你好恶魔请更换
alertContentView.backgroundColor = UIColor.black
alert.view.subviews.first?.subviews.first?.subviews.first?.backgroundColor = .black
它将解决您的问题。