我想为我的应用程序中的现有pdf文件添加密码保护。
这是我的代码:
if let path = Bundle.main.path(forResource: "pdf_file", ofType: "pdf") {
let url = URL(fileURLWithPath: path)
if let pdfDocument = PDFDocument(url: url) {
pdfDocument.write(to: url, withOptions: [PDFDocumentWriteOption.userPasswordOption : "pwd"])
pdfView.displayMode = .singlePageContinuous
pdfView.autoScales = true
// pdfView.displayDirection = .horizontal
pdfView.document = pdfDocument
}
}
Run Code Online (Sandbox Code Playgroud)
查看文件之前添加了pdfDocument.write()行。我期望该文件将不再被查看,或者在查看该文件之前会先询问密码,但是我仍然可以直接查看该文件,就像该行不存在一样。
我在将密码保护添加到pdf文件之前和之后尝试过PSPDFKit,当查看该文件时,它会先询问密码,并且应用程序存储中的文件已被锁定/加密,但这不是我使用此iOS时得到的内容iOS 11及更高版本的PDFKit新功能。
我想以我的段落的标题为中心并加粗.到目前为止,我可以使标题大胆,但我不能把它放在中心位置.
这是我的代码:
let title = "Title of Paragraph"
let attrs = [NSFontAttributeName : UIFont.boldSystemFontOfSize(15)]
let boldString = NSMutableAttributedString(string:title, attributes:attrs)
let normalText = "Something here.............."
let attributedString = NSMutableAttributedString(string:normalText)
boldString.appendAttributedString(attributedString)
label.attributedText = boldString
Run Code Online (Sandbox Code Playgroud)
我试图在attrs中添加另一个属性:
let attrs = [NSFontAttributeName : UIFont.boldSystemFontOfSize(15), NSTextAlignment: NSTextAlignment.Center]
Run Code Online (Sandbox Code Playgroud)
我不确定这是否是以它为中心的正确方法,但它仍然会给出错误"表达类型不明确而没有更多上下文"
我搜索了错误,但似乎我仍然无法解决问题