首页 > 解决方案 > 如何更改 iOS 系统警报的色调?

问题描述

我想更改 iOS 系统警报的色调颜色,例如要求访问照片库或 AppStore 审查的警报(不是您以编程方式创建和呈现的 UIAlertController),但我不知道这是否可能。

像这样使用窗口色调颜色不起作用:

self.window?.tintColor = UIColor.red

更改我的视图控制器视图的色调颜色也不起作用。

如果有可能怎么办?

标签: iosiphoneswiftuikitios11

解决方案


这是(Swift 4)的工作代码

tintColor1.在 AppDelegate 中更改应用。

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

    self.window?.tintColor = UIColor.red
    return true
}

tintColor2.从 ViewController更改应用程序。

let alert = UIAlertController(title: "Alert", message: "This is an alert.", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
alert.view.tintColor = UIColor.red
self.present(alert, animated: true, completion: nil)

推荐阅读