如何在 Cocoa 下正确设置下划线类型

How to properly set underline type under Cocoa

全部,

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]

你能帮忙吗?

[/编辑]

您缺少下划线样式。

[attrs setObject:[NSNumber numberWithInt:( NSUnderlineStyleSingle | NSUnderlinePatternDot )] forKey:NSUnderlineStyleAttributeName];