1
UITextView
показывает форматированный текст, когда я использую NSAttributedString
:UITextView и NSMutableAttributedText
NSAttributedString* s1 =
[[NSAttributedString alloc] initWithString:@"Hello there!"
attributes:@{NSForegroundColorAttributeName:[UIColor redColor], NSFontAttributeName: [UIFont preferredFontForTextStyle:UIFontTextStyleBody]}];
_textView.attributedText = s1;
Однако, когда я использую NSMutableAttributedString
я вижу прилагается приписываемые строки без форматирования. Форматирование будет показано для строки, которая была инициализирована только.
UIFont *font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody]
NSMutableAttributedString *emailBody = [[NSMutableAttributedString alloc] initWithString:@"" attributes:@{NSForegroundColorAttributeName:[UIColor redColor], NSFontAttributeName: font}];
if (_person.firstName.length > 0) {
[emailBody appendAttributedString:[[NSAttributedString alloc]initWithString:_person.firstName attributes:@{NSFontAttributeName: [UIFont preferredFontForTextStyle:UIFontTextStyleCaption1]}]];
[emailBody appendAttributedString:[[NSAttributedString alloc]initWithString:@"\n" attributes:nil]];
}
if (_person.lastName.length > 0) {
[emailBody appendAttributedString:[[NSAttributedString alloc]initWithString:_person.lastName attributes:@{NSFontAttributeName: [UIFont preferredFontForTextStyle:UIFontTextStyleCaption2]}]];
[emailBody appendAttributedString:[[NSAttributedString alloc]initWithString:@"\n" attributes:nil]];
}
Почему?