我要显示过多修改的长文本.. 大文本包含特殊字符。每当特殊字符出现在下面时,行应该是粗体,并且应该生成\ n应该生成新标签。
答案 0 :(得分:2)
试试这个:你可以在value参数中添加任何字体样式。使用这个你可以为substring添加样式,使其与普通字符串不同。
NSString *strFirst = @"Anylengthtext";
NSString *strSecond = @"Anylengthtext";
NSString *strThird = @"Anylengthtext";
NSString *strComplete = [NSString stringWithFormat:@"%@ %@ %@",strFirst,strSecond,strThird];
NSMutableAttributedString *attributedString =[[NSMutableAttributedString alloc] initWithString:strComplete];
[attributedString addAttribute:NSForegroundColorAttributeName
value:[UIColor whiteColor]
range:[strComplete rangeOfString:strFirst]];
[attributedString addAttribute:NSForegroundColorAttributeName
value:[UIFont fontWithName:@"Roboto-Regular" size:12]
range:[strComplete rangeOfString:strSecond]];
[attributedString addAttribute:NSForegroundColorAttributeName
value:[UIColor blueColor]
range:[strComplete rangeOfString:strThird]];
self.lblName.attributedText = attributedString;