I am trying to highlight a row in an NSTableView using a CALayer. I would like the surrounding rows to fade to a darker color when a specific row is clicked, so that the selected row is clearly in focus and highlighted.
I am not sure how to best achieve this, but my initial thought was first to incorporate my NSTableView into a Custom View and allow the view layer to have CALayer abilities. I could then track the location of the mouse within that view and if the user clicks, I know the location of the click relative to the [layer bounds] and I can highlight the areas above and below (e.g., 10 points) where the user clicked for the entire width. However, the user may not click perfectly in the middle of the row, which would create a skewed highlighing area.
My questions is: is there a better way to do this? Can NSTableView do CALayer in an easy way that enables me to highlight a specific row by putting a gradient on the remaining rows that are visible? Can I avoid the background Custom View?
I think you’d be better off creating a custom
NSTableCellsubclass that can handle the color change, then you don’t have to worry about mouse tracking or lining things up with the table at all.With your idea you’d need to track the current position of the table view’s scrollers and adjust your highlight to suit. Sounds like a nightmare.