Does NSTableHeaderView add a row?

For my first Mac application, I am trying to create a simple window with a table view. I have included the headers, but adds an annoying line on top of my NSTableHeaderView :

enter image description here

I cannot find a property to remove it. I know that it can be deleted because the Finder does not have it:

enter image description here

When I turn off the Headers, there is no border there. It should also be noted that NSTableView is inside NSSplitView . Any ideas?

+4
source share
2 answers

The problem exists, because both the window frame and the scroll view in the form of a table have a border of 1px. Depending on your layout, you can either set borderStyle to an NSScrollView , which NSTableView your NSTableView in an NSNoBorder (note that this will remove the 1px border from all sides of the scroll). Or you can move the scroll view by 1px.

0
source

Another solution:

  • Subclass NSTableHeaderView
  • Override -drawRect: to draw a 1pt white line horizontally at the top to match the background color of the table title.
  • Create an instance of the custom header using -initWithFrame: passing in the existing headerView frame.
  • Give the custom header a view of the headerView table.

Implementation of -drawRect: ::

 - (void)drawRect:(NSRect)dirtyRect { // Allow the table header view to draw itself [super drawRect:dirtyRect]; // Draw a 1pt white line across the width of the header view [[NSColor whiteColor] setFill]; NSRectFill(NSMakeRect(0.0f, 0.0f, self.bounds.size.width, 1.0)); } 
+1
source

Source: https://habr.com/ru/post/1382982/


All Articles