macos - 如何在 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。
我错过了什么?
蒂亚!
[编辑]:
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];
推荐阅读
- angular - ngModel 为不同的字段显示相同的值
- sql - 从某个组中获取最后一个值(Oracle)
- reactjs - Native Base 两个头文件
- php - 动态 PHP 表过滤和排序
- extjs - 将值从一个视图发送到另一个 ExtJS 4
- javascript - 单击 SVG 后如何与另一个 SVG 交互
- php - wp_kses 清理正在删除有效的字体系列名称
- javascript - Firefox 桌面浏览器的画布中断,Chrome 桌面只有在加载 cookie 时才能正常工作
- c# - 如何正确递归此对象列表?
- c# - 在 C# 中完成程序后,在类析构函数中关闭 SqlConnection 是否安全?