Pergunta

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:[self 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.

Foi útil?

Solução

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

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top