简体   繁体   English

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

[英]How to change the tint color of iOS system alerts?

I want to change the tint color of the iOS system alerts like the alert that ask for the photo library access or an AppStore review (not UIAlertController that you create and present programmatically) but I don't know if it is possible. 我想更改iOS系统警报的色调颜色,例如要求照片库访问的警报或AppStore评论(不是您以编程方式创建和呈现的UIAlertController),但我不知道是否可能。

Using the window tint color like this don't work: 使用这样的窗口色调颜色不起作用:

self.window?.tintColor = UIColor.red

Changing the tint color of the view of my view controller also don't work. 更改视图控制器视图的色调颜色也不起作用。

If it is possible how to do it? 如果有可能怎么办?

This isn't possible, since the system manages the creation of these alerts. 这是不可能的,因为系统管理这些警报的创建。 You can only specify the text in the permission alerts using the key-val pair in the info.plist file. 您只能使用info.plist文件中的key-val对在权限警报中指定文本。 This is probably restricted for consistent UI. 这可能仅限于一致的UI。

Here is Working Code for (Swift 4) 这是(Swift 4)的工作代码

1. Change the app tintColor in the AppDelegate. 1.在AppDelegate中更改app tintColor

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

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

2. Change the app tintColor from ViewController. 2.从ViewController更改app 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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM