iphone - iOS 5 中的 NSAttributedString 设置文本字体和背景

标签 iphone ios objective-c ipad

<分区>

Possible Duplicate:
how to set attributes in NSAttributedString in iOS?

我有以下代码:

 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 中做同样的事情怎么办?我必须为此使用第三方库吗?

最佳答案

您可以深入了解 iOS 5 的 Core Text。Core Text 比 NSAttributedString 更强大,但它的文档也更少,工程师也更难访问。

关于iphone - iOS 5 中的 NSAttributedString 设置文本字体和背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14353178/

相关文章:

iphone - 我可以使用此代码依赖此 "default"更新间隔(加速计)吗?

iphone - 返回后释放对象吗?

ios - XCode 性能测量

ios - 如何使用 FLAnimatedImage 检查动画的结束

iphone - 将 UITableView 与 NSMutableArray 链接

ios - 与今天的扩展共享 SQLite 不起作用

ios - UITableView:如何通过长按更改自定义单元格中的 UIView 状态?

iphone - 可以在cocos2d中使用UIPickerView吗?

iphone - setNeedsDisplay并不总是调用drawRect

iphone - 培训 iPhone 开发人员