all,
NSMutableDictionary* constattrs = [NSMutableDictionary dictionaryWithCapacity:5];
[attrs setObject:[NSNumber numberWithInt:( NSUnderlinePatternDot )] forKey:NSUnderlineStyleAttributeName];
[attrs setValue:style.GetUnderlineColour() forKey:NSUnderlineColorAttributeName];
[m_textView setTypingAttributes:attrs];
上面的代码编译并执行,但视图中的文本不会被下划线。
我在OSX 10.13下进行测试,最低要求10.9。
我缺少什么?
tia!
[编辑]:
NSRange range = NSMakeRange(start, end-start);
NSTextStorage* storage = [m_textView textStorage];
if( style.HasFontUnderlined() )
{
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
[dict setObject:[NSNumber numberWithInt:( NSUnderlinePatternDot )] forKey:NSUnderlineStyleAttributeName];
[dict setValue:style.GetUnderlineColour() forKey:NSUnderlineColorAttributeName];
[storage addAtributes:dict range:range];
[dict release];
我会在上述代码上发出汇编警告:
warning: instance method '-addAtributes:range:' not found (return type defaults to 'id'); did you mean '-addAttributes:range:'? [-Wobjc-method-access]
您可以帮忙吗?
[/edit]
您缺少下划线样式。
[attrs setObject:[NSNumber numberWithInt:( NSUnderlineStyleSingle | NSUnderlinePatternDot )] forKey:NSUnderlineStyleAttributeName];