UITextView attributed text not working when using custom font

前端 未结 2 1423
梦毁少年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条回答
  •  梦毁少年i
    2021-01-14 12:37

    Instead of setting the font outside of the attributed text, try setting all the font changes at once inside of the attributed string:

    NSMutableAttributedString *mutAttrTextViewString = [[NSMutableAttributedString alloc] initWithString:_textView.text];
    [mutAttrTextViewString setAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"BurbankSmall-Medium" size:16] range:NSMakeRange(0, _textView.text.length)];
    [mutAttrTextViewString setAttributes:dictBoldText range:rangeBold];
    [mutAttrTextViewString setAttributes:dictBoldText range:rangeBold2];
    [mutAttrTextViewString setAttributes:dictBoldText range:rangeBold3];
    
    [_textView setAttributedText:mutAttrTextViewString];
    

提交回复
热议问题