LoginSignup
16
10

More than 3 years have passed since last update.

UITextView UILabel で Times New Romen が使用される

Last updated at Posted at 2019-10-08

環境

Xcode 11.1
Swift 4.2
iOS13

事象

最新の環境で、ビルドするとUITextView UILabelのテキストが、明朝体風の Times New Romen へ変わってしまう問題が発生しました。

スクリーンショット 2019-10-08 18.05.18.png

Xib上は、System を指定できている。
スクリーンショット 2019-10-09 1.45.22.png

期待値では、SFUI-Regularが使用されるはずが、
スクリーンショット 2019-10-09 1.41.54.png

Debug View Hierarchy上で確認してみると Times New Romen というフォントが設定されてしまう。
スクリーンショット 2019-10-08 17.59.00.png

暫定対応

NSAttributedStringを使う方法とFontを再設定する方法があります。
あくまで暫定対応なので、アップデートで治る可能性もあるため、急いで直したい場合は、以下で対応できました。


let stringAttributes: [NSAttributedStringKey : Any] = [.font : UIFont.systemFont(ofSize: 14.0)]
textView.attributedText = NSAttributedString(string: "text", attributes: stringAttributes)

or


// customクラスを作成する
class SystemFontTextView: UITextView {
    override var text: String! {
        didSet {
             font = UIFont.systemFont(ofSize: font?.pointSize ?? 14)
        }
    }
}

参考

System font renders as Times New Roman in certain contexts

追記:2019/10/08 18:30 現在、iOS 13.1.2

Xcode 11.1でも直らない

追記:2020/05/15/ 18:00

CoreTextのログが出るが、使えている

[23824:577523] CoreText note: Client requested name ".PingFangSC-Regular", it will get TimesNewRomanPSMT rather than the intended font. All system UI font access should be through proper APIs such as CTFontCreateUIFontForLanguage() or +[UIFont systemFontOfSize:].
16
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16
10