Я пытаюсь зарегистрировать шрифт, который был получен из UIDocument, все отлично работает
I enabled Install Fonts capability under the Signing & Capabilities
и I accessed the UIDocument file and I pick the font.
, но я не знаю, как его зарегистрировать.
Это мой код
@objc func didPressButton(_ sender: UIButton) {
let documentPicker: UIDocumentPickerViewController = UIDocumentPickerViewController(documentTypes: ["public.truetype-ttf-font", "public.opentype-font"], in: UIDocumentPickerMode.import)
documentPicker.delegate = self
self.present(documentPicker, animated: true, completion: nil)
}
// MARK: - UIDocumentPickerDelegate Methods
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
let fontUrl = Bundle(for: type(of : self)).path(forResource: "\(urls[0].path)", ofType: nil)
CTFontManagerRegisterFontURLs([fontUrl] as CFArray, .persistent, true) { (errors, done) -> Bool in
if(done) {
print("Done")
}
print(errors as Array)
for family in UIFont.familyNames.sorted() {
let names = UIFont.fontNames(forFamilyName: family)
print("Family: \(family) Font names: \(names)")
}
return true
}
}
func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController) {
controller.dismiss(animated: true, completion: nil)
}