1

In my AppDelegate I configure my navigation bar as follows:

func setupNavBar() {
    let barAppearance = UINavigationBar.appearance()
    barAppearance.titleTextAttributes = [NSAttributedString.Key.foregroundColor: appRed]
    barAppearance.setBackgroundImage(UIImage(), for: UIBarMetrics.default)
    barAppearance.shadowImage = UIImage()
    barAppearance.isTranslucent = true
}

This works well - until I want to display a UIImagePickerController from one of my UIViewControllers - the images go beyond the bar as its translucent - I need to be able to temporarily make the nav bar white, and then make it translucent again when the picker controller is dismissed:

enter image description here

I tried fixing this by adding the last two lines to the code:

 let pickerController = UIImagePickerController()
    pickerController.delegate = self
    pickerController.allowsEditing = false
    pickerController.mediaTypes = ["public.image"]
    pickerController.sourceType = .savedPhotosAlbum
    self.navigationController?.navigationBar.backgroundColor = .white
    self.navigationController?.navigationBar.isTranslucent = false
    self.present(pickerController, animated: true, completion: nil)

This doesn't seem to work though.

Alk
  • 5,215
  • 8
  • 47
  • 116

1 Answers1

1

Try this:

let pickerController = UIImagePickerController()
pickerController.delegate = self
pickerController.allowsEditing = false
pickerController.mediaTypes = ["public.image"]
pickerController.sourceType = .savedPhotosAlbum
UINavigationBar.appearance().isTranslucent = false
self.present(pickerController, animated: true, completion: nil)

And on image picker dismiss

UINavigationBar.appearance().isTranslucent = true
souvickcse
  • 7,742
  • 5
  • 37
  • 64