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

3

7

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!

Wide answered 7/4, 2015 at 9:0 Comment(1)
Notice the description of your scroll view: "Bordered Scroll View - Table View". Check the attributes of the scroll view and turn off the border. The 1-pixel divider is probably from the split view.Rive
M
13

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

Molini answered 7/4, 2015 at 11:10 Comment(0)
E
2

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.

Erine answered 17/8, 2016 at 17:10 Comment(0)
Z
0

To whoever wants to remove the NSTableView border...

My requirement was to remove the border colour of the NSTableView so that, it should look like a white box. Tried all properties and forums but couldn't find a way to do that. Finally I came up with a dirty hack in the Storyboard which could fix the problem. If someone have a better option, please let us know.

  1. Embed the NSTableView in a CustomBox. Set the Box BorderType as 'None'
  2. Then set the constraints (Left, Top, Right and Bottom) of NSTableView to the containing Box. Set the values to -2. so that the NSTableView border will be outside of the Box
  3. Now in Storyboard, select the 'clipView(NSClipView)' of the NSTableView. clipView is the superView of the NSTableView
  4. Go to the Size Inspector and uncheck the 'Automatically Adjust' property of the "Content Insets"
  5. Set the values to Left=2, Top=2, Bottom=-2 and Right=-2

Thats it.

Zuckerman answered 31/8, 2017 at 16:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.