QLPreviewController更改标题? [英] QLPreviewController change title?

查看:303
本文介绍了QLPreviewController更改标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以更改QLPreviewController中项目的标题?

Is it possible to change the title of an item in an QLPreviewController?

我已经尝试过:


  1. 子类化QLPreviewController

  2. 添加

  1. Subclassing QLPreviewController
  2. Add

override func viewDidAppear(_ animated: Bool) {
  self.navigationController?.navigationBar.topItem?.title = "Bericht"
}


但是你只看到1/4秒的标题。

But you see the title only for maybe 1/4 second.

任何想法?

推荐答案

如果你需要在url中显示除lastPathComponent之外的其他标题,你可以继承QLPreviewItem并提供你自己的标题来实现可选属性:

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:

实例属性声明:

var previewItemTitle: String? { get }




预览项目的标题。

The title to display for the preview item.

如果你没有为这个属性实现getter方法,或者你的
方法返回nil,QuickLook将检查
项的URL或内容预览以确定显示给
用户的适当标题。返回此属性的非零值以提供自定义
标题。

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

QLPreviewItem协议定义了您实现的属性,使您的
应用程序的内容在QuickLook预览中可见
(iOS中的QLPreviewController或QLPreviewPanel中的QLPreviewController)苹果系统)。此协议中的方法
也在NSURL类中声明为类别。
因此,您可以直接使用NSURL对象作为预览
项目 - 前提是您要使用这些项目的默认标题。
默认标题是项目URL的最后一个路径组件。如果
想要提供您自己的预览项目标题,请创建您自己的采用此协议的预览
项目对象。

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.

第一个子类QLPreviewItem:

First Subclass QLPreviewItem:

import UIKit
import QuickLook
class PreviewItem: NSObject, QLPreviewItem {
    var previewItemURL: URL?
    var previewItemTitle: String?
}

然后在您的控制器中返回QLPreviewItem而不是URL:

Then in your controller you return the QLPreviewItem instead of the URL:

import UIKit
import QuickLook

class ViewController: UIViewController, QLPreviewControllerDelegate, QLPreviewControllerDataSource {
    let item = PreviewItem()
    override func viewDidLoad() {
        super.viewDidLoad()
        item.previewItemTitle = "Custom Title"
        item.previewItemURL = Bundle.main.url(forResource: "your file", withExtension: "ext")
    }
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        quickLook()
    }
    func numberOfPreviewItems(in controller: QLPreviewController) -> Int {
        return 1
    }
    func quickLook() {
        let preview = QLPreviewController()
        preview.delegate = self
        preview.dataSource = self
        preview.currentPreviewItemIndex = 0
        present(preview, animated: true)
    }
    func previewController(_ controller: QLPreviewController, previewItemAt index: Int) -> QLPreviewItem {
        return  item
    }
}

这篇关于QLPreviewController更改标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆