我到处搜索,但找不到如何更改 NSTextView 中字体颜色的解决方案? Xcode/Interface Builder 中当然有一个选项,但编译时我不会更改颜色。但背景颜色确实发生了变化。 我必须子类化 TextView 吗?
最佳答案
尝试做这样的事情:-
(IBAction) colorTest: (id) sender{
[mText insertText: @"red" color: [NSColor redColor]];
[mText insertText: @" " color: [NSColor blackColor]];
[mText insertText: @"green" color: [NSColor greenColor]];
[mText insertText: @" " color: [NSColor blackColor]];
[mText insertText: @"blue" color: [NSColor blueColor]];
[mText insertText: @" " color: [NSColor blackColor]];
}
或者您尝试将其设置为默认颜色,如下所示:-
NSFont* font = <whatever>;
[textView setFont: font];
或
[[myNSTextView textStorage] setFont:[NSFont fontWithName:@"Menlo" size:11]];
关于xcode - 如何更改 NSTextView 中的字体颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13550626/