如何更改 UIImagePicker 中的导航栏标题?

How to change navigation bar title in UIImagePicker?

我正在 Swift 写作,所以我找不到足够的信息来解决这个问题。

无论如何,我一切正常,即:显示照片库选择视图,编辑工作正常,裁剪图像导出到图像视图。

我的问题确实是当视图以模态方式呈现时,标题说 "Photos"。我该如何将其更改为其他内容?

var imagePicker = UIImagePickerController()
imagePicker.navigationItem.title = "MY TITLE"

更改标题文本属性有效,但不能更改标题本身。

让自己成为 imagePicker 的委托并实现:

func navigationController(navigationController: UINavigationController, willShowViewController viewController: UIViewController, animated: Bool) {
    viewController.navigationItem.title = "asdf"
}

在此处找到:Changing NavigationBar Title of UIImagePickerController

Swift 4

func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {
                viewController.navigationItem.title = "asdf"
      }