-1

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

4

1 回答 1

3

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

你肯定在寻找NSAttributedString


源头

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;
于 2013-02-26T14:51:25.053 回答