A brief.
Split view, a view that arranges two or more views in a linear stack running horizontally or vertically.
The default is horizontal
@interface NSSplitView : NSView
Copy the code
2. Official attribute method
// delegate @property (nullable, weak) id<NSSplitViewDelegate> delegate; - (BOOL)splitView:(NSSplitView *)splitView canCollapseSubview:(NSView *)subview; / / whether to allow users to folding and unfolding the specified child view - (void) splitView: (NSSplitView *) splitView resizeSubviewsWithOldSize (NSSize) oldSize; / / child views according to the custom size - (void) splitViewWillResizeSubviews (NSNotification *) notification; / / will adjust the child view big hours notice to entrust - (void) splitViewDidResizeSubviews (NSNotification *) notification; - (BOOL)splitView:(NSSplitView *)splitView canCollapseSubview:(NSView *)subview; // whether to resize the subview - (CGFloat)splitView:(NSSplitView *)splitView constrainMinCoordinate:(CGFloat)proposedMinimumPosition ofSubviewAt:(NSInteger)dividerIndex; // Allows the client to limit the minimum coordinate limit when the user drags the separator line. - (CGFloat)splitView:(NSSplitView *)splitView constrainMaxCoordinate:(CGFloat)proposedMaximumPosition ofSubviewAt:(NSInteger)dividerIndex; // Allows the client to limit the minimum coordinate limit when the user drags the separator line. - (CGFloat)splitView:(NSSplitView *)splitView constrainSplitPosition:(CGFloat)proposedPosition ofSubviewAt:(NSInteger)dividerIndex; // Allows delegates to restrict the dividing line to certain locations. // @property BOOL arrangesAllSubviews API_AVAILABLE(macOS (10.11)); // @property BOOL arrangesAllSubviews API_AVAILABLE(macOS (10.11)); @property (readonly, copy) NSArray<__kindof NSView *> *arrangedSubviews API_AVAILABLE(macOS (10.11)); // addArrangedSubview:(NSView *)view API_AVAILABLE(macos(10.11)); // addArrangedSubview:(NSView *)view API_AVAILABLE(macos(10.11)); - (void)insertArrangedSubview (NSView *)view atIndex (NSInteger)index API_AVAILABLE(macOS (10.11)); // insert split pane into specified index - (void)removeArrangedSubview:(NSView *)view API_AVAILABLE(macos(10.11)); AdjustSubviews - (void)adjustSubviews; // subview collapsed - (BOOL)isSubviewCollapsed:(NSView *)subview; / / return whether in a folding state - (NSLayoutPriority) holdingPriorityForSubviewAtIndex: (NSInteger) subviewIndex API_AVAILABLE (macos (10.8)); // Resize the subview, Returns the priority of width or height - (void)setHoldingPriority:(NSLayoutPriority)priority forSubviewAtIndex:(NSInteger)subviewIndex API_AVAILABLE (macos (10.8)); @property (Nullable, copy) NSSplitViewAutosaveName autosaveName API_AVAILABLE(MacOS (10.5)); // The system automatically saves the name used in the separator configuration of the split view. @property (getter=isVertical) BOOL vertical; @property NSSplitViewDividerStyle dividerStyle API_AVAILABLE(macos(10.5)); / / line style, the typedef NS_ENUM (NSInteger NSSplitViewDividerStyle) {NSSplitViewDividerStyleThick = 1, NSSplitViewDividerStyleThin = 2, NSSplitViewDividerStylePaneSplitter API_AVAILABLE (macos (10.6)) = 3, } API_AVAILABLE (macos (10.5)); @property (readonly, copy) NSColor *dividerColor API_AVAILABLE(macOS (10.5)); // Line color @property (readonly) CGFloat dividerThickness; // dividerinrect - (void) drawerinrect :(NSRect)rect; / / draw the line / / limit split position about < > (or up and down) on slide area - (CGFloat) minPossiblePositionOfDividerAtIndex dividerIndex: (NSInteger) API_AVAILABLE (macos (10.5)); / / index minimum position - (CGFloat) maxPossiblePositionOfDividerAtIndex: (NSInteger) dividerIndex API_AVAILABLE (macos (10.5)); // the maximum position at the index - (void)setPosition:(CGFloat)position ofDividerAtIndex:(NSInteger)dividerIndex API_AVAILABLE(macos(10.5)); // Sets the position of the split line at the specified indexCopy the code
Iii. Example < code >
Creating an NSSplitView in code, if you want to create it in Storyboard, it’s easier
- (NSSplitView *)splitView { if (! _splitView) { _splitView = [[NSSplitView alloc] initWithFrame:CGRectMake(10, 100, 600, 400)]; _splitView.delegate = self; _splitView.vertical = YES; _splitView.dividerStyle = NSSplitViewDividerStylePaneSplitter; _splitView.wantsLayer = YES; _splitView.layer.backgroundColor = NSColor.whiteColor.CGColor; _splitView.toolTip = @" code creates SplitView"; } return _splitView; } - (void)viewDidLoad { [super viewDidLoad]; // Do view setup here. self.view.wantsLayer = YES; self.view.layer.backgroundColor = NSColor.lightGrayColor.CGColor; [self addSplitView]; } - (void)addSplitView { NSView *leftView = [[NSView alloc] initWithFrame:CGRectMake(0, 0, 100, 400)]; [self.splitView addArrangedSubview:leftView]; NSView *rightView = [[NSView alloc] initWithFrame:CGRectMake(100, 0, 500, 400)]; [self.splitView addArrangedSubview:rightView]; [self.view addSubview:self.splitView]; } - (CGFloat)splitView:(NSSplitView *)splitView constrainMinCoordinate:(CGFloat)proposedMinimumPosition ofSubviewAt:(NSInteger)dividerIndex { return 100; } - (CGFloat)splitView:(NSSplitView *)splitView constrainMaxCoordinate:(CGFloat)proposedMaximumPosition ofSubviewAt:(NSInteger)dividerIndex { return 200; } - (BOOL)splitView:(NSSplitView *)splitView canCollapseSubview:(NSView *)subview {return YES; }Copy the code