Insert NSTableView Content View

I want to insert the contents of an NSTableView so that there is a space between the top view of the table and the first cell.

On iOS, this is easy with a UITableView - achieved with setContentInset :.

+3
source share
4 answers

Include headers and replace the header view with your own subclass. Override it with -drawRect: draw only your background color. Also, override -headerRectOfColumn: to prevent drawing any column heading. I'm not sure if this will prevent the columns from being dragged or sorted, but I'm betting it does.

+1
source

, , . heightOfRow:

- (CGFloat)tableView:(NSTableView *)tableView heightOfRow:(NSInteger)row 
{
  if (row == 0) {
    return normalRowHeight + topPadding;
  } else {
    return normalRowHeight;
  }
}

, , .

0

, , iOS. , , . , iOS. "" .

NSTableView . macOS NSScrollView. NSTableView, enclosingScrollview NSView, :

( Obj-C )

    self.enclosingScrollView.automaticallyAdjustsContentInsets = NO;
    self.enclosingScrollView.contentInsets = NSEdgeInsetsMake(50.f,0.f,0.f,0.f);

viewDidLoad , .

NSOutlineView, , , , Finder. "" - . , , NSOutlineView setFrameSize: . ( NSOutlineView):

- (void)setFrameSize:(NSSize)newSize {
    [super setFrameSize:newSize];
    self.enclosingScrollView.automaticallyAdjustsContentInsets = NO;
    self.enclosingScrollView.contentInsets = NSEdgeInsetsMake(100.f,0.f,0.f,0.f);
}

, . scrollToBeginningOfDocument: initWithCoder: .

0
scrollView.automaticallyAdjustsContentInsets = false
scrollView.contentInsets = NSEdgeInsets(top: 40, left: 0, bottom: 0, right: 0)
-1

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


All Articles