ios - UIAlertController 的外观

标签 ios uialertcontroller uiappearance

我想在应用程序中使用外观设置我的 AlertController 的外观。 它适用于背景和按钮,但无论我尝试什么,标题和消息的标签始终保持黑色。

这是我正在做的:

UIView.appearance(whenContainedInInstancesOf: [UIAlertController.self]).tintColor = .orange
UIVisualEffectView.appearance(whenContainedInInstancesOf: [UIAlertController.self]).effect = UIBlurEffect(style: .dark)
UILabel.appearance(whenContainedInInstancesOf: [UIAlertController.self]).textColor = .white

这是我得到的结果:

enter image description here

任何想法,如何设置标题和消息的颜色,或者为什么更改 UILabel 的外观在这种情况下不起作用?

最佳答案

最简单的方法是:不要。

您绝对不必局限于使用 UIAlertController 及其简单的默认 View 外观和内容。毕竟,它不过是一个呈现的 View Controller 。这意味着可以编写您自己的呈现 View Controller ,其外观和行为几乎类似于 UIAlertController 及其 View ,只是现在您完全负责其内容!

编写自己的类似警报的呈现 View Controller 比尝试侵入 UIAlertController 的 View 要好得多、更容易、也更可靠;前者是完全合法的,而后者除了不可靠之外,还可能导致您的应用程序被 App Store 禁止。

关于ios - UIAlertController 的外观,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53770631/

相关文章:

ios - 运行旧的 iOS 版本 XCode

ios - PresentViewController 不工作

ios - 操作表 IOS 中的分段控制

ios - swift -IOS : UIalertController position

iOS:带有 UIViewControllerBasedStatusBarAppearance 的默认状态栏样式 YES

ios - 如何通过外观协议(protocol)设置 UIBarButtonItem 的 tintColor?

swift - 更改 UILabel 的大小会更改其字体名称

ios - 需要在 UICollectionView 中显示视频和图片

ios - 具有多个操作的 UIButton : How to prevent other actions from firing

ios - xcode "A valid provisioning profile for this executable was not found"