Filling around an NSTableView

I have the following problem. There is a subclass NSScrollView with an NSTableView view in it. I added a special background to scrollview in the -drawRect: method of the subclass, and now I would like to add some โ€œindentationโ€ around the inner table view as follows:

example http://img.skitch.com/20120117-ktd9g5wy8u9cm37jeebjjxx61u.png

How can i implement this?

+4
source share
4 answers

Finally, I solved the problem. I created an NSView (called documentContentView on it), added my NSTableView as a subtask of this DocumentContentView, after which I added documentContentView to the scrollview of documentView:

NSTableView *docView = (NSTableView *)self.scrollView.documentView; id newClipView = [[CustomClipView alloc] initWithFrame:[self.scrollView.contentView frame]]; [self.scrollView setContentView:(NSClipView *)newClipView]; [newClipView setDrawsBackground:NO]; NSView *documentContentView = [[NSView alloc] initWithFrame:docView.bounds]; docView.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable; [documentContentView addSubview:docView]; [self.scrollView setDocumentView:documentContentView]; [self.scrollView setDrawsBackground:NO]; 

I created my custom NSClipView called CustomClipView (based on this article http://www.cocoadev.com/index.pl?CenteringInsideNSScrollView ), and this subclass sets the start of documentContentView when the window changes. I also subclassed my desktop and in the -reloadData method I can resize the documentContentView when its change in the table has changed.

+2
source

First of all, do not add backgrounds to drawRect: Add it to your initWithFrame: if you subclass it or change it from the caller.

Adding a pad is very simple: change the frame to an NSTableView so that it is smaller and has a coordinate origin that is not 0.0.

+1
source

Left and right filling can be done inside the row / cell itself. For the top and bottom fill, I suggest adding extra lines without content and not selecting. It is not sexy, but worked for me.

+1
source

If you are targeting Mac OS 10.10 or later, you can use

 [scrollView setAutomaticallyAdjustsContentInsets:NO]; [scrollView setContentInsets:NSEdgeInsetsMake(top, right, bottom, left)]; 
+1
source

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


All Articles