我目前正在開發一個 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
}
只有當我啟動應用程式時,我才會得到這個渲染:
渲染黑色
背景顏色不是黑色。但是,當我更改 UIColor 時,例如:
alertContentView.backgroundColor = UIColor.green
渲染是正確的:
渲染綠色
盡管在網上進行了研究,但我找不到解決方案。
謝謝你的時間 :)
uj5u.com熱心網友回復:
你好惡魔請替換
alertContentView.backgroundColor = UIColor.black
為alert.view.subviews.first?.subviews.first?.subviews.first?.backgroundColor = .black
它會解決你的問題。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/482885.html
上一篇:mat-button-toggle'不是已知元素:即使在將匯入添加到app.module.ts之后
下一篇:打開視窗時編輯文本
