ios - 我的导航栏、警报标题和底部警报标题在整个项目中变成白色

标签 ios swift iphone uinavigationcontroller alert

我的导航栏、警报标题和底部警报标题在整个项目中变成白色。我找到的答案仅适用于单个警报,但不适用于全局警报。

enter image description here

2

  func inliseAlert(_ imageSelection:Int,_ VC:UIViewController ,_ success:@escaping ImageSelectionCompletion) {
//Change color of selection overlay to white
    viewController = VC
    numberOfImage = imageSelection
    self.success = success
    let imageSourceAlert = UIAlertController(title: "Choose Image", message: "", preferredStyle: UIAlertController.Style.actionSheet)
   
    let camera = UIAlertAction(title: "Camera", style: .default) { [weak self](action: UIAlertAction) in
                   // Code to unfollow
                   DispatchQueue.main.async {
                       self?.openCamera()
                   }
               }
   
           let gallery = UIAlertAction(title: "Gallery", style: .default) {[weak self] (action: UIAlertAction) in
               // Code to unfollow
            guard let self = self else {return }
               DispatchQueue.main.async {
                   self.openGallery()
               }
           }
   
   
           let cancelAction = UIAlertAction(title: "Cancel", style: .destructive, handler: nil)
           imageSourceAlert.addAction(camera)
           imageSourceAlert.addAction(gallery)
           imageSourceAlert.addAction(cancelAction)
   
         //  if let topController = UIApplication.getTopViewController() {
               viewController?.present(imageSourceAlert, animated: true, completion: nil)
          // }
}

最佳答案

这是一些奇怪的行为...... 从您发布的屏幕截图来看,您似乎正在模拟器上运行,我会确保并检查设备上的行为,以排除任何奇怪的情况。

假设该行为在设备上持续存在:

我注意到的第一件事是代码中的注释:

//Change color of selection overlay to white

我会仔细研究它所指的内容以及该过程中发生的情况。

比如前面出现的评论:

viewController = VC // I think the tintColor of viewController is causing this unwanted behavior

然后当您显示您正在调用的警报时:

 //  if let topController = UIApplication.getTopViewController() {
               viewController?.present(imageSourceAlert, animated: true, completion: nil)
          // }

viewController 和 TopViewController 是一样的吗? 如果没有,我想我会尝试:

 if let topController = UIApplication.getTopViewController() {
            topController.present(imageSourceAlert, animated: true, completion: nil)
        }

还要检查呈现的 ViewController 上的tintColor,尝试在呈现警报之前更改它。

查看行为是否发生变化。

如果没有:

我会在您的代码和 Storyboard中查看 tintColor 的使用。 还可以在代码中查找 appearance() 的使用。

我建议,因为我能想到的全局更改 textColor 的唯一方法(不使用扩展)类似于

UIApplication.shared.keyWindow?.tintColor = .white

UILabel.appearance().textColor = .white

就此而言,我会查看 UIAlertControllerUIViewController 在项目中是否有任何扩展,以及它们是否确实仔细查看了那里发生的情况。

此外,ABV 建议查找并检查 UIColor 的任何使用,尤其是 .white.clear

如果所有都失败并且您找不到原因,也许您可​​以使用上面的代码/建议来扭转效果,但是我强烈建议查找并纠正找出根本原因,而不是添加更多解决方法来解决问题。

如果无法访问该项目,这实际上是一个猜谜游戏。

关于ios - 我的导航栏、警报标题和底部警报标题在整个项目中变成白色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66542236/

相关文章:

运行 flutter 升级后iOS模拟器性能不佳

ios - 如何将 ITF 条码用于钱包通行证?

android - 在 iOS 和 Android 上点赞支付

node.js - 如何优雅地在 Swift 中实现 EventEmitter

swift - 在 Swift 3 中使用溢出运算符

iphone - AVPlayerItem 失败并显示 AVStatusFailed 和错误代码 "Cannot Decode"

ios表格单元格左侧细节不是动态大小

Swift:Realm - 在将数据添加到数据库时更新 UI(进度)

iphone - 当 UIView 低于 EAGLView 时,我的性能是否会受到很大影响?

iphone - 是否有类似 "Codea"的应用程序,但用于 MonoTouch?