简体   繁体   English

设置NSTextView选择字体名称

[英]Setting NSTextView selection font name

I can change the selected text font name in a text view as: 我可以在文本视图中将选定的文本字体名称更改为:

NSMutableDictionary *attributes = [[NSMutableDictionary alloc] init];
[attributes setObject: [NSFont fontWithName:"Tahoma" size:20] forKey:
    NSFontAttributeName];
[[textView textStorage] setAttributes:attributes range:[textView selectedRange]];

Above code works only if I have selection range. 以上代码仅在我具有选择范围的情况下有效。 If my text view has no selection the code has no effect and typing font does not change. 如果我的文本视图没有选择,则代码无效,并且键入字体不会更改。 I want to change the font at cursor (if text view has no selection) and not whole of text view. 我想更改光标处的字体(如果文本视图没有选择),而不是整个文本视图。 (like text edit) any help would be appreciated. (例如文本编辑),我们将不胜感激。

您可以使用-[NSTextView setTypingAttributes:]更改将应用​​于新输入文本的属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM