Mac OSX:如何在NSTextField中划分文本?

时间:2016-09-23 20:44:43

标签: objective-c macos

我使用Objective C为OSX编写应用程序。我有一个NSTextField,我用它来显示不可编辑的文本。我试图让字体周围有一个薄的笔划/轮廓,但很难这样做。

我尝试使用NSTextView而不是NSTextField并实现了NSAttributedString,但文本根本没有概述:

            NSAttributedString *string = [[NSAttributedString alloc] initWithString:@"Test String" attributes:@{ NSStrokeColorAttributeName : [CIColor blackColor], NSForegroundColorAttributeName : [CIColor blackColor], NSStrokeWidthAttributeName : @-1.0 }];

            [quoteText_Label setEditable:YES];
            [quoteText_Label insertText: string];
            [quoteText_Label setEditable:NO];

看看SO的另一个问题,他们要么针对iOS,要么是Swift,要么是我试图去做的简单实现的过度杀戮:只是围绕白色字体的简单黑色笔触。

谢谢

2 个答案:

答案 0 :(得分:1)

在XIB中启用Rich Text并设置文本字段的attributedStringValue属性。您不必执行setEditable

阅读NSStrokeWidthAttributeName的文档:

  

包含浮点值的NSNumber,占字体磅值的百分比

     

默认为0,无中风;积极的,只有中风;负,笔画和填充(轮廓文本的典型值为3.0)

黑色文字周围的黑色黑色轮廓几乎看不见。

答案 1 :(得分:0)

颜色属性的值应为NSColor对象。我认为,使用CIColor是错误的。