Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSScrollView padding

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!

like image 726
Alex Marchant Avatar asked Jan 26 '13 02:01

Alex Marchant


2 Answers

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.

like image 173
Alex Marchant Avatar answered Sep 21 '22 01:09

Alex Marchant


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)
  }
}
like image 22
Clifton Labrum Avatar answered Sep 22 '22 01:09

Clifton Labrum