我使用三个类将文本绘制到屏幕上: NSTextStorage、NSTextContainer和NSLayoutManager。我希望nstextstorage的一部分具有一些特殊属性(下划线、颜色...)但它不起作用。代码如下:
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])];问题是它引发了这个异常: NSConcreteNotifyingMutableAttributedString addAttribute: value :range::nil value
你能帮帮我吗?
提前谢谢。
编辑:我通过更正方法调用解决了异常。但是,属性不会显示。
发布于 2011-01-21 01:54:56
[self defaultFont]返回什么值?看起来可能是零。
https://stackoverflow.com/questions/4750669
复制相似问题