Reputation: 225
I've made an NSTableCellView in my nib, which has the textField occupying the entire space, and it works great for displaying text, and tracking the size of the column.
Now I want to be able to set a solid background color for it, in a specific case (i.e., not for all cells). How do I do this?
I think it's like this question, except the solution there didn't do anything for me, and I can't come up with anything close to it that works, either.
I've tried making my -tableView:viewForTableColumn:row:
method...
Since my text takes up the entire cell view, being able to set it on either the textField or the whole cell view would be fine.
This seems like it should be a simple setting somewhere, but nothing works. Do I need to subclass NSTableCellView just to have a background color?
Upvotes: 1
Views: 1923
Reputation: 202
I will recommend to create a subclass of NSTableCellView. It helps in creating a re-usable component(you can even add a gradient to make it look different) and segregating the responsibilities. You can use this simple code and change the class in NSTableCellView.
- (void)drawRect:(NSRect)dirtyRect
{
NSRect bounds = [self bounds];
[[NSColor redColor] set];
NSRectFill(bounds);
}
Upvotes: 3