Search code examples
iosswiftiphoneuinavigationcontrolleralert

My Navigation bar and Alert title and Bottom Alert title became white in whole project


My Navigation bar and Alert title and Bottom Alert title became white in whole project. I found answers only which are only perform on individual alerts but not as Global.

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)
          // }
}

Solution

  • Thats some strange behavior... From the screen shots you posted it looks like you were running on the simulator, I would make sure and check the behavior on a device just to rule out any strangeness.

    Assuming the behavior persists on a device:

    The first thing I notice is the comment in your code that says:

    //Change color of selection overlay to white
    

    I would look closely at what's that is referring to and what's happening in that process.

    Such as the comment appears just before:

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

    and then when you present the alert you are calling:

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

    Are viewController and TopViewController the same?? if not I think I would try:

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

    Also check the tintColor on the presenting ViewController try changing it before presenting the alert.

    See if the behavior changes.

    If it doesn't:

    I would be looking at uses of tintColor in your code and storyboards. Also maybe look for uses of appearance() in your code.

    I suggest that because the only way to change that textColor globally I can think of (without use of an extension) would be something like

    UIApplication.shared.keyWindow?.tintColor = .white
    

    or

    UILabel.appearance().textColor = .white
    

    For that matter I would look to see if UIAlertController or UIViewController had any extensions in the project and if they do take a close look to what's happening there.

    Also as ABV suggested look for and examine any use of UIColor especially .white or .clear.

    If ALL else fails and you can't find the cause maybe you can use the above code/suggestions to reverse the effect, however I strongly suggest finding and correcting the root cause rather than adding more workarounds to fix the issue.

    Without access to the project it is really a guessing game.