3

可能重复:
如何在 iOS 的 NSAttributedString 中设置属性?

我有以下代码:

 comment = [[NSMutableAttributedString alloc] initWithString:self.highlightItem_.comment];
            [comment addAttribute:NSFontAttributeName value:[UIFont fontWithName:kProximaNovaBold size:15] range:nameRange];
            [comment addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:128/255.f green:203/255.f blue:255/255.f alpha:1.0] range:nameRange];

            [comment addAttribute:NSFontAttributeName value:[UIFont fontWithName:kProximaNova size:15] range:commentRange];
            [comment addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithWhite:153/255.f alpha:1.0] range:commentRange];

然而,这是一个 iOS 6 代码,如果我想在 iOS 5 中做同样的事情怎么办。我必须为此使用第三方库吗?

4

1 回答 1

0

您可以下拉到 iOS 5 的 Core Text。Core Text 比 Core Text 更强大,NSAttributedString但它的文档也较少,工程师也不太容易访问。

于 2013-01-16T07:23:37.913 回答