我使用 NSTextField 而不是 NSTextView 来接收用户输入,但我需要自定义字体、文本颜色和行距。我使用下面的代码,字体和颜色都可以,但我不知道如何设置行距。
[self.titleField setTextColor:textColor];
[self.titleField setFont:bold14];
Run Code Online (Sandbox Code Playgroud)
我还使用 NSAttributedString 来解决问题:
NSFont *bold14 = [NSFont boldSystemFontOfSize:14.0];
NSColor *textColor = [NSColor redColor];
NSMutableParagraphStyle *textParagraph = [[NSMutableParagraphStyle alloc] init];
[textParagraph setLineSpacing:10.0];
NSDictionary *attrDic = [NSDictionary dictionaryWithObjectsAndKeys:bold14, NSFontAttributeName, textColor, NSForegroundColorAttributeName, textParagraph, NSParagraphStyleAttributeName, nil];
NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:title attributes:attrDic];
[self.titleField setAllowsEditingTextAttributes:YES];
[self.titleField setAttributedStringValue:attrString];
Run Code Online (Sandbox Code Playgroud)
上面的代码可以显示属性字符串,但是当我删除文本字段中的字符串并开始输入时,这些单词没有任何属性。
如何在 NSTextField 中输入具有自定义字体、颜色和行距的字符串?
我正在开发一个Mac应用程序,我想绘制一个像雷达一样的视图,我找不到沿着弧线绘制渐变颜色的方法.现有方法仅向一个方向绘制渐变.