如何在nstextview中设置文本的背景颜色?

3 cocoa objective-c nsattributedstring

我有一个nstextview,我想知道如何设置它的背景颜色.我尝试过很多东西,但似乎都没有用.他们只是设置实际的文本颜色.我有一个名为的NSColorWell,如果有人想知道的话,会调用colorBoxtextview doc.我使用`[self.colorBox color]来获取NSColorWell中的颜色

Eon*_*nil 5

NSTextView拥有backgroundColor财产.尝试将其设置为其他类似的东西NSColor.redColor().

它还具有需要设置的drawsBackground属性true才能使其工作.

let textView1 = NSTextView()
textView1.backgroundColor = NSColor.redColor()
textView1.drawsBackground = true
Run Code Online (Sandbox Code Playgroud)