6
votes

I have an NSScrollView with an NSTableView inside.

enter image description here

As you can see, there is a 100px high NSView that overlays the table view. (This is done intentionally, the overlay is slightly transparent and you can see a shadow of the table view scroll underneath).

The problem of course is that I need to add 100px of empty space to the bottom of the scroll view to compensate for the overlay. Otherwise you can't see the bottom of the table, it gets covered up by the overlay.

I've tried modifying the clip view, but seem to only be able to change its frame (losing the transparent overlay effect).

Maybe I'm not doing it quite right, please help!

2
Just a thought. What if you increase scrollViews contentSize by 100px after you do reloadData. Another thought would be to add empty row to match overlay.Evgeny Shurakov
@EvgeniyShurakov I tried subclassing the scroll view and overriding the contentSize method and adding 100px to the height. Is that the correct way to do this? It had no effect for me.Alex Marchant

2 Answers

7
votes

Ok so I figured it out, I needed to consistently enlarge the documentView frame.

The best way I found to do this was to subclass the document view, which in this case is the NSTableView.

In the subclassed NSTableView I overrode the setFrameSize:(NSSize)newSize

- (void)setFrameSize:(NSSize)newSize {
    newSize.height += 100;
    [super setFrameSize:newSize];
}

Which added 100px of padding to the bottom of the table view and thus the scroll view.

1
votes

Here's the same thing in Swift 4:

class TableViewPadded: NSTableView{
  //Add padding at bottom
  override func setFrameSize(_ newSize: NSSize) {
    let padded = NSSize(width: newSize.width, height: newSize.height+30)
    super.setFrameSize(padded)
  }
}