How to set the custom title in QLPreviewController in iOS Swift

QLPreviewController is the easiest option to enable a preview of a wide range of documents in an iOS application. The document you want to preview using QLPreviewController is called as previewItem.

By default, QLPreviewController sets the previewItem title based on the last component in the given URL. When you have your server to generate the document for you and they might name it using timestamp which is tough for the normal user to understand it.

You can set your custom name for the previewItem in this case. You need to create CustomPreviewItem class which conforms QLPreviewItem protocol to set the custom name for the preview item.

Then you can use your CustomPreviewItem in previewItemAt index: method,

Thanks! 👨🏻‍💻

--

--