我想在应用程序中使用外观设置我的 AlertController 的外观。 它适用于背景和按钮,但无论我尝试什么,标题和消息的标签始终保持黑色。
这是我正在做的:
UIView.appearance(whenContainedInInstancesOf: [UIAlertController.self]).tintColor = .orange
UIVisualEffectView.appearance(whenContainedInInstancesOf: [UIAlertController.self]).effect = UIBlurEffect(style: .dark)
UILabel.appearance(whenContainedInInstancesOf: [UIAlertController.self]).textColor = .white
这是我得到的结果:
任何想法,如何设置标题和消息的颜色,或者为什么更改 UILabel 的外观在这种情况下不起作用?
最佳答案
最简单的方法是:不要。
您绝对不必局限于使用 UIAlertController 及其简单的默认 View 外观和内容。毕竟,它不过是一个呈现的 View Controller 。这意味着您可以编写您自己的呈现 View Controller ,其外观和行为几乎类似于 UIAlertController 及其 View ,只是现在您完全负责其内容!
编写自己的类似警报的呈现 View Controller 比尝试侵入 UIAlertController 的 View 要好得多、更容易、也更可靠;前者是完全合法的,而后者除了不可靠之外,还可能导致您的应用程序被 App Store 禁止。
关于ios - UIAlertController 的外观,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53770631/