I need to do some advanced text styling of NSTextFieldCell
First i need some background color on the text only. Like the headers in the F-Script Browser
Setting [cell setBackgroundColor: [NSColor blueColor]]; colors the whole cell space not only the text. Also i would need underlined and strikeout text. And to make things readable i would finally like to c开发者_如何学编程hange the colors (foreground/background) of the selection on the styled items.
Can i do this with the default NSTextFieldCell ?
Nearly all of these things are jobs for NSAttributedString. As long as the text field cell has rich text enabled, it should accept an attributed string as its object value just fine.
As for the selection color, remember that an NSTextFieldCell is a kind of NSActionCell, and an NSActionCell is a kind of NSCell. NSCells have a method you can override to return a different highlight color. That covers the background; for the foreground, you may have to draw at least the highlighted portion yourself. You may be able to make good use of blend modes in that method.
精彩评论