QLPreviewController change title?
If you need to display a different title other than the lastPathComponent from your url, you can subclass QLPreviewItem and provide your own title implementing the optional property:
Instance Property Declaration:
var previewItemTitle: String? { get }
The title to display for the preview item.
If you do not implement a getter method for this property, or if your
method returns nil, QuickLook examines the URL or content of the item
being previewed to determine an appropriate title for display to the
user. Return a non-nil value for this property to provide a custom
title.
protocol QLPreviewItem : NSObjectProtocol
Description
The QLPreviewItem protocol defines properties you implement to make your
application’s content visible in a QuickLook preview
(QLPreviewController in iOS or QLPreviewPanel in macOS). The methods
in this protocol are also declared as a category on the NSURL class.
As a result, you can use NSURL objects directly as preview
items—provided that you want to use the default titles of those items.
A default title is the last path component of an item’s URL. If you
want to supply your own preview item titles, create your own preview
item objects that adopt this protocol.
First Subclass QLPreviewItem:
import UIKit
import QuickLook
class PreviewItem: NSObject, QLPreviewItem {
var previewItemURL: URL?
var previewItemTitle: String?
init(url: URL? = nil, title: String? = nil) {
previewItemURL = url
previewItemTitle = title
}
}
Then in your controller you return the QLPreviewItem instead of the URL:
Xcode 11 • Swift 5.1
import UIKit
import QuickLook
class ViewController: UIViewController, QLPreviewControllerDelegate, QLPreviewControllerDataSource {
var previewItems: [PreviewItem] = []
override func viewDidLoad() {
super.viewDidLoad()
previewItems = [
.init(url: Bundle.main.url(forResource: "your file 1", withExtension: "ext"),
title: "Custom Title 1"),
.init(url: Bundle.main.url(forResource: "your file 2", withExtension: "ext"),
title: "Custom Title 2"),
]
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
quickLook()
}
func numberOfPreviewItems(in controller: QLPreviewController) -> Int { previewItems.count }
func quickLook(at index: Int = 0) {
let controller = QLPreviewController()
controller.delegate = self
controller.dataSource = self
controller.currentPreviewItemIndex = index
present(controller, animated: true)
}
func previewController(_ controller: QLPreviewController, previewItemAt index: Int) -> QLPreviewItem { previewItems[index] }
}
qlpreviewcontroller navigation bar - How to Change pageCount to String
Try this
let lblNavTitle = UILabel(frame: CGRect(x: 60, y: 10, width: view.frame.size.width-110, height: 20))
lblNavTitle?.textAlignment = .center
lblNavTitle?.lineBreakMode = .byTruncatingMiddle
lblNavTitle?.text = "File Name"
navigationItem.titleView = lblNavTitle
OR
Simply set title property like
self.title = "File Name"
May be it will work for you
Change navigation bar color in QLPreviewController
I have used below code to Change navigation bar color of QLPreviewController in swift 3.0
UINavigationBar.appearance().barTintColor = UIColor.red
UINavigationBar.appearance(whenContainedInInstancesOf: [QLPreviewController.self]).backgroundColor = UIColor.red
QLPreviewController customise the title color of the navigation bar?
You can do it with appearance
Like this :
[[UINavigationBar appearance] setTitleTextAttributes:
@{NSForegroundColorAttributeName: [UIColor whiteColor]}];
Quicklook/QLPreviewController shows a blank page instead of pdf on ios 8 but works fine on iOS7
This is actually a known issue in iOS 8 Beta 5.
See the URL under QuickLook
https://developer.apple.com/library/prerelease/ios/releasenotes/General/RN-iOSSDK-8.0/
Related Topics
How to Find the Kind of Errors a Method May Throw and Catch Them in Swift
How to Prevent a Remote Notification from Being Displayed
How to Parse Array of JSON to Array in Swift
Pinch to Zoom Effect on Uiimageview Inside Scrollview
Fonts Not Displaying in Interface Builder
Apple Watch - Only Getting Data If App on Phone Is Active
How to Change a Swiftui Color to Uicolor
Building Ffmpeg iOS Libraries for Armv7, Armv7S, Arm64, I386 and Universal
How to Make a Mkannotationview Touch Sensitive
Gssendevent - Inject Touch Event iOS
How to Get Assets.Xcassets File Names in an Array (Or Some Data Structure)
How to Display Uiview Over Keyboard in iOS
Universal Links Not Working on iOS10
Initwithstyle:Reuseidentifier: Not Called
Swift Put Multiple Iboutlets in an Array
Can an iOS App Switch the Device to Silent Mode
iOS Uitableview with Dynamic Text and Images Rendered Together (Nsattributedstring + Images)