How to make UIImagePickerController StatusBar lightContent style?

前端 未结 7 1622
悲哀的现实
悲哀的现实 2020-12-29 12:53

\"enter

When I present the ImagePickerController the statusBar text color is still bla

相关标签:
7条回答
  • 2020-12-29 13:54

    Swift solution by writing an extension for UIImagePickerController:

    extension UIImagePickerController {
        convenience init(navigationBarStyle: UIBarStyle) {
            self.init()
            self.navigationBar.barStyle = navigationBarStyle
        }
    }
    

    Then you can set the color when initializing it:

    let picker = UIImagePickerController(navigationBarStyle: .black)    // black bar -> white text
    

    Alternative (inspired by folse's answer): When you initialize the UIImagePickerController normally, make this class the delegate (picker.delegate = self) and implement this function:

    func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) {
        if navigationController is UIImagePickerController {        // check just to be safe
            navigationController.navigationBar.barStyle = .black    // black bar -> white text
        }
    }
    
    0 讨论(0)
提交回复
热议问题