Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Draw NSTableView Alternating Rows Like iTunes 11

I am aware that there are other questions on SO about changing alternating row colors. That's easy and it's not what I want to do.

I want to draw custom alternating-colored rows in a view-based NSTableView that look like those from iTunes 11 (slight bezel at the top and bottom of the row, as shown in this screenshot):

iTunes 11 screenshot

NOTE:

I know I can subclass NSTableRowView and do my custom drawing there. However, this is NOT an acceptable answer because the custom row will only be used for rows that have data in the table. In other words, if the table has only 5 rows, those 5 rows will use my custom NSTableRowView class but the remaining "rows" in the rest of the table (which are empty) will use the standard alternating colors. In that case, the first 5 rows will show the bezel and the remaining ones won't. Not good.

So, how can I hack NSTableView to draw these styled alternating rows for both filled and empty rows?

like image 707
Bryan Avatar asked Jan 06 '13 01:01

Bryan


1 Answers

you can use

- (void)setUsesAlternatingRowBackgroundColors:(BOOL)useAlternatingRowColors

with useAlternatingRowColors YES to specify standard alternating row colors for the background, NO to specify a solid color.

like image 118
aka Crow Avatar answered Oct 22 '22 15:10

aka Crow