Drawing text using NSTextStorage
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.
精彩评论