如何更改iOS系统警报的色调颜色?

时间:2018-08-11 10:20:33

标签: ios iphone swift uikit ios11

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

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

self.window?.tintColor = UIColor.red

更改视图控制器的视图颜色也无效。

如果有可能怎么做?

2 个答案:

答案 0 :(得分:2)

这是不可能的,因为系统管理这些警报的创建。您只能使用info.plist文件中的key-val对指定权限警报中的文本。对于一致的UI,这可能受到限制。

答案 1 :(得分:1)

以下是(快捷键4)

的工作代码

1。在AppDelegate中更改应用tintColor

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

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

2。从ViewController更改应用tintColor

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)
相关问题