【发布时间】:2019-06-26 04:00:43
【问题描述】:
所有,
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]
你能帮忙吗?
[/编辑]
【问题讨论】:
-
您想给现有文本加下划线吗?
NSUnderlineStyleSingle有效吗? -
@Willeke,不 - 将写入视图的文本
-
如何将文本写入视图?
-
@Willeke,我正在调用 `[m_textView insertText:wxCFStringRef
]。
标签: macos styles nstextview