UIFontPickerViewController

一个视图控制器,显示用于在CloudKit共享记录中添加和删除人员的标准屏幕。

class UIFontPickerViewController : UIViewController

使用教程

使用UIFontPickerViewController为用户提供对其设备上所有字体的访问权限。 直接查询UIFont仅提供系统字体,但用户的设备上可能有其他字体。 当用户在字体选择器中选择这些非系统字体之一时,系统会授予您的应用对字体的访问权限。

字体选择器具有收集到UIFontPickerViewController.Configuration对象中的几个自定义选项。 例如,可以将includeFaces设置为true,以便用户不仅可以选择字体,还可以选择该字体系列中的粗体或斜体。 首先自定义配置对象,然后在字体选择器的init(configuration :)方法中将其作为参数传递。

func showFontPicker(_ sender: Any) {
        let fontConfig = UIFontPickerViewController.Configuration()
        fontConfig.includeFaces = true
        let fontPicker = UIFontPickerViewController(configuration: fontConfig)
        fontPicker.delegate = self
        self.present(fontPicker, animated: true, completion: nil)
    }

当您的UIFontPickerViewControllerDelegate接收fontPickerViewControllerDidPickFont(_ :)时,请从字体选择器的selectedFontDescriptor中检索有关用户所选字体的信息。

**

实战代码

SwiftUI 2.0 实战之文本字体选择组(封装UIFontPickerViewController)