Ios 在TextView中为文本添加颜色

Ios 在TextView中为文本添加颜色,ios,xcode,Ios,Xcode,我有一个文本视图,其中我需要一些文本来更改颜色和字体。除核心文本外,任何方法都可用。请帮忙 我需要一些文字来改变颜色和字体 你当然在找 从 您想从所有文本中更改一些文本,对吗?您应该可以通过搜索internet轻松找到问题的答案。 NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"Hello. That is a test attributed string."]; [str

我有一个文本视图,其中我需要一些文本来更改颜色和字体。除核心文本外,任何方法都可用。请帮忙

我需要一些文字来改变颜色和字体

你当然在找



您想从所有文本中更改一些文本,对吗?您应该可以通过搜索internet轻松找到问题的答案。
NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"Hello. That is a test attributed string."];
[str addAttribute:NSBackgroundColorAttributeName value:[UIColor yellowColor] range:NSMakeRange(3,5)];
[str addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(10,7)];
[str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaNeue-Bold" size:20.0] range:NSMakeRange(20, 10)];
label.attributedText = str;