UITextView attributed text not working when using custom font

前端 未结 2 1420
梦毁少年i
梦毁少年i 2021-01-14 12:32

I\'m using UITextView and I\'m setting its font and attributed text by code.

Case 1: Custom-font - YES , attribtued text<

2条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-14 12:44

    There is a related question here.
    The main issue is that font (UIFont) property of UITextView is to be applied for its text (NSString) property (also named "plain text") and not for the attributedText (NSAttributedString).

    So you have to applied the "normal" font effect to your NSAttributedString yourself.

    So just replace:

    NSMutableAttributedString *mutAttrTextViewString = [[NSMutableAttributedString alloc] initWithString:_textView.text];
    

    with:

    NSMutableAttributedString *mutAttrTextViewString = [[NSMutableAttributedString alloc] initWithString:_textView.text attributes:@{NSFontAttributeName:[UIFont fontWithName:@"BurbankSmall-Medium" size:16]}];
    

提交回复
热议问题