开发者

Drawing text using NSTextStorage

开发者 https://www.devze.com 2023-02-06 00:50 出处:网络
I\'m drawing text to the screen using the three classes: NSTextStorage, NSTextContainer, NSLayoutManager.

I'm drawing text to the screen using the three classes: NSTextStorage, NSTextContainer, NSLayoutManager. I want one part of the nstextstorage to have some special attributes (underline, color...) but it doesn't work. Here is the code:

NSTextStorage *textStorage= [[NSTextStorage alloc] initWithString:string];
int fromLength= [[[pub from] name] length];
[textStorage addAttribute:NSUnderlinePatternSolid  value:NSUnderlineStyleAttributeName range:NSMakeRange(0, fromLength)];
[textStorage addAttribute:NSFontAttributeName value:[se开发者_高级运维lf defaultFont] range:NSMakeRange(0, [textStorage length])];

The problem is that it raises this exception: NSConcreteNotifyingMutableAttributedString addAttribute:value:range:: nil value

Can you help me?

Thanks in advance.

EDIT: I resolved the exception by correcting the method call. The attributes are not displayed though.


What value does [self defaultFont] return? It looks like it might be nil.

0

精彩评论

暂无评论...
验证码 换一张
取 消