objective-c – CATextLayer不绘制NSAttributedString背景颜色

我有CATextLayer,并希望将背景颜色设置为字符串的一部分.但是将背景颜色设置为属性字符串(NSBackgroundColorAttributeName)没有任何效果.正确应用其他属性,例如前景色.

NSMutableAttributedString *str = [[[NSMutableAttributedString alloc] initWithString:@"Some Text"] autorelease];
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
                            [NSColor yellowColor],NSForegroundColorAttributeName,[NSColor redColor],NSBackgroundColorAttributeName,nil];

[str setAttributes:attributes range:NSMakeRange(0,3)];

textLayer.string = str;

前三个符号以黄色绘制,但背景不会改变.有任何想法吗?

解决方法

我认为CATextLayer类使用CoreText API进行渲染. CoreText API非常低级,仅支持NSAttributedString属性的子集.不幸的是,NSBackgroundColorAttributeName不是其中之一.你必须手动处理它(见 this SO entry).

相关文章

我正在用TitaniumDeveloper编写一个应用程序,它允许我使用Ja...
我的问题是当我尝试从UIWebView中调用我的AngularJS应用程序...
我想获取在我的Mac上运行的所有前台应用程序的应用程序图标....
我是一名PHP开发人员,我使用MVC模式和面向对象的代码.我真的...
OSX中的SetTimer在Windows中是否有任何等效功能?我正在使用...
我不确定引擎盖下到底发生了什么,但这是我的设置,示例代码和...