Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove NSTableView's border and change cell selection color as same as Finder's?

I'm making an Cocoa app for Yosemite.

I added a view based NSTableView in Interface builder, but the border 2 pixel width and thicker than Yosemite's Finder's. And the cell selection color is blue, while Yosemite's Finder's is gray.

enter image description here

enter image description here

And this is how Yosemite's Finder's table view looks like.

enter image description here

I checked the settings in Interface Builder. The super scroll view of NSTableView's frame setting is (0,0,149,257): enter image description here

While the Clip View's frame setting is (1, 1, 147, 255) and can not be changed.

enter image description here

And how to make a same NSTableView as Yosemite's Finder's?

Thanks a ton!

like image 253
OpenThread Avatar asked Apr 07 '15 09:04

OpenThread


2 Answers

The Finder sidebar isn't a table-view it's a Source List NSOutlineView:

enter image description here

The border is applied around the enclosing scroll view:

enter image description here

Note also that a standard NSOutlineView lets you adjust the highlight style from within Interface Buider:

enter image description here

like image 85
Paul Patterson Avatar answered Oct 13 '22 18:10

Paul Patterson


In my experience selected rows are still painted blue, even when the "Source List" highlight style is selected. To avoid that, I needed to prevent the table or outline view from becoming the first responder by subclassing it and adding

- (BOOL)becomeFirstResponder {
    return NO;
}

Edit: Turns out becomeFirstResponder is actually important if you want to support keyboard navigation. I have found a better solution that does not override becomeFirstResponder.

First, create a custom NSTableRowView subclass with an (overridden) empty setEmphasized: method:

- (void)setEmphasized:(BOOL)emphasized {
    // This avoids a blue background when selected in a source list that has first responder status.
}

You can then provide an instance of your custom NSTableRowView class by implementing

- (NSTableRowView *)tableView:(NSTableView *)tableView rowViewForRow:(NSInteger)row

in your NSTableViewDelegate.

like image 2
MrMage Avatar answered Oct 13 '22 18:10

MrMage