Another solution is to:
- Subclass
NSTableHeaderView
- Override
-drawRect:
to draw a 1pt white line horizontally across the top to match the table header view's background color.
- Instantiate an instance of the custom header view using
-initWithFrame:
passing in the existing headerView
's frame.
- Assign the custom header view to the table view's
headerView
property.
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));
}
Or in Swift:
override func draw(_ dirtyRect: NSRect) {
super.draw(dirtyRect)
let topBorderBox = NSRect(x: 0, y: 0, width: bounds.size.width, height: 1)
if dirtyRect.intersects(topBorderBox) {
NSColor.white.setFill()
topBorderBox.fill()
}
}