首页 > 解决方案 > 将“动态字体大小”与 NSAttributedString 一起使用

问题描述

我正在尝试保存并稍后显示使用动态字体大小显示的格式化 NSAttributedString: UIFont.preferredFont(forTextStyle: .body)。我目前:

  1. 创建 UITextView 并将其字体大小设置为UIFont.preferredFont(forTextStyle: .body)
  2. 在 UITextView 中输入文本时,字体显示为<UICTFont: 0x13de36a90> font-family: "UICTFontTextStyleBody"; font-weight: normal; font-style: normal; font-size: 17.00pt
  3. 保存 NSAttributedString
  4. 再次打开并加载 UITextView 时,字体显示为<UICTFont: 0x142a86f60> font-family: ".SFUI-Regular"; font-weight: normal; font-style: normal; font-size: 17.00pt

我在这里错过了什么吗?您是否无法将UIFont.preferredFontNSAttributedString 中的字体另存为字体。我只是在加载时重新添加字体,但这不起作用,因为字符串的属性丢失了(粗体、斜体等)。

标签: iosswiftnsattributedstringtextkit

解决方案


推荐阅读