如何在UIDocumentPicker的导航栏中设置图像?

时间:2019-04-09 13:09:37

标签: ios swift uidocumentpickervc

我想在UIDocumentPicker的导航栏中添加图像。

我尝试使用以下代码:

var documentPicker = UIDocumentPickerViewController(documentTypes: ["com.adobe.pdf","com.apple.rtfd"], in: .import)
iewController.navigationItem.hidesBackButton = false;
documentPicker.navigationItem.leftBarButtonItem?.tintColor = ConfigurationParameters.textColor
documentPicker.navigationController?.navigationBar.isTranslucent = false
documentPicker.navigationController?.navigationBar.tintColor = UIColor.black
documentPicker.navigationItem.titleView?.backgroundColor = UIColor.white

let bannerHeight = documentPicker.navigationController?.navigationBar.frame.height
print(viewController.navigationController?.navigationBar.frame.height)
let logoContainer = UIView(frame: CGRect(x: 0, y: 0, width: 200, height: bannerHeight ?? 44.0 * 1.0))
let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 200, height: bannerHeight ?? 44.0 * 1.0))

let logo =  UIImage(named: "Resource.bundle/xyz.me", in: Bundle(for: ViewController.self), compatibleWith: nil)
imageView.image = logo
imageView.contentMode = .scaleAspectFill
logoContainer.addSubview(imageView)
documentPicker.navigationItem.titleView  = logoContainer

0 个答案:

没有答案