I'm using the "Alternating Rows" option in Interface Builder to get alternating row colors on an NSTableView. Is there any way to change the colors of the alternating rows?
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- back button text does not change
- iOS (objective-c) compression_decode_buffer() retu
- how to find the index position of the ARRAY Where
相关文章
- 现在使用swift开发ios应用好还是swift?
- Visual Studio Code, MAC OS X, OmniSharp server is
- TCC __TCCAccessRequest_block_invoke
- xcode 4 garbage collection removed?
- IntelliJ IDEA can't open projects or add SDK o
- Automator: How do I use the Choose from List actio
- Xcode: Is there a way to change line spacing (UI L
- Unable to process app at this time due to a genera
I'm not sure how recently this was added, or if it is as flexible as you need it to be, but I noticed that you can specify "Alternating" rows in Interface Builder in Xcode 4.6 (and possibly earlier).
NSTableView
orNSOutlineView
Highlight Alternating Rows
checkbox.I wanted a solution that worked just like the regular
NSTableView
, including support for elastic scrolling and such, so I created anNSTableView
subclass that has anNSColor*
property calledalternateBackgroundColor
, and then overrode the-drawBackgroundColorInClipRect:
method like so:There is no settable property for this, however you can respond to the delegate method
-tableView:willDisplayCell:forTableColumn:row:
and set the cell's background color based on the evenness of the row number.I subclassed NSTableView and implemented drawRow:clipRect: like this...
It seems to work, but it's so simple that I'm wondering if I'm missing something.
Nate Thorn's answer worked perfectly for me.
Here it is, refactored for Swift:
Found a better way to do it here. That method overrides the highlightSelectionInClipRect: method in an NSTableView subclass so you can use any color you want for the alternating rows. It's not as hackish as using an NSColor category, and it only affects table views you choose.