I\'m using UITextView
and I\'m setting its font and attributed text by code.
Case 1: Custom-font - YES , attribtued text<
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];
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]}];