【问题标题】:How to change the tint color of iOS system alerts?如何更改 iOS 系统警报的色调?
【发布时间】:2018-08-11 10:20:33
【问题描述】:

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

像这样使用窗口色调是行不通的:

self.window?.tintColor = UIColor.red

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

如果可以怎么办?

【问题讨论】:

    标签: ios iphone swift uikit ios11


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      这是 (Swift 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)
      

      【讨论】:

      • 我在问题中提到 self.window?.tintColor 不适用于 iOS 系统警报,它不是您可以以编程方式创建的 UIAlertController 而是呈现的但 iOS 请求用户敏感的数据。
      • 我知道@adrgrondin self.window?.tintColor = UIColor.red 你在应用程序委托文件中提到的警报和操作表都可以正常工作。
      • 它适用于您创建的 UIAlertController 是的,我知道,但不适用于 iOS 提出的请求例如访问照片库的警报。尝试调用 SKStoreReviewController.requestReview() 来查看示例,窗口色调颜色未应用于警报。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-20
      相关资源
      最近更新 更多