For my first Mac app, I'm trying to make a simple window with just a table view. I enabled Headers but it adds an annoying line on top of my NSTableHeaderView
:
I can't seem to find a property to remove it. I know it can be removed, because the Finder doesn't have it:
When I disable Headers, the border is not there. I should also note that the NSTableView
is located inside an NSSplitView
. Any ideas?
Another solution is to:
NSTableHeaderView
-drawRect:
to draw a 1pt white line horizontally across the top to match the table header view's background color.-initWithFrame:
passing in the existing headerView
's frame.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()
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With