我需要在我的iOS项目中编写一个自定义字体选择器视图。当用户点击字体族名称时,我需要显示该族的字体,我把族名作为特定文本样式。但我无法找到获取特定名称文本样式名称的标准方法,请帮助我解决这个问题。
例如,我已经比较了所有字体名称和
例如,我已经比较了所有字体名称和
UIFontPickerViewController
iOS组件的字体名称。 如果我打印族名和字体名称,如下所示,针对Times New Roman
族。Family name Times New Roman
Font name: TimesNewRomanPS-ItalicMT
Font name: TimesNewRomanPS-BoldItalicMT
Font name: TimesNewRomanPS-BoldMT
Font name: TimesNewRomanPSMT
但是在UIFontPickerViewController
(iOS组件)中,它显示为如下形式:
我想知道,我们怎样从上面打印的名称中获取文本样式Regular, Italic, Bold, Bold Italic
?
请帮忙解答并感谢您的反馈。
以下是源代码以供比较。
import UIKit
class ViewController: UIViewController, UIFontPickerViewControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
let familyNames = UIFont.familyNames.sorted()
for family in familyNames {
print("Family name " + family)
let fontNames = UIFont.fontNames(forFamilyName: family)
for font in fontNames {
print(" Font name: " + font)
}
}
let configuration = UIFontPickerViewController.Configuration()
configuration.includeFaces = true
configuration.displayUsingSystemFont = true
configuration.filteredTraits = [.classModernSerifs]
let vc = UIFontPickerViewController(configuration: configuration)
vc.delegate = self
present(vc, animated: true)
}
}