top accessory view

This commit is contained in:
Suresh, Kamlesh 2019-11-14 18:15:22 -05:00
parent 835eb3a43b
commit f1b8a61e04
2 changed files with 33 additions and 5 deletions

View File

@ -38,6 +38,8 @@
#pragma mark - Subclass
- (nullable NSArray *)topAccessoryViews;
// Allow you to add any additional ui before buildViewsBetweenLabelsAndButtons gets called. Can use this to set the topBetweenEdgeView or bottomBetweenEdgeView
- (void)buildInAdditionalViewsBeforeCenteredContent;
// For subclassing. Should return all the views that will be in between labels and buttons. Override standardSpaceAroundUIObject to handle spacing.

View File

@ -101,7 +101,13 @@
// Removes the bottom view out of scroll if it is there.
[self.viewOutOfScroll removeFromSuperview];
[StackableViewController removeUIViews:[self.contentView subviews]];
UIView *topAccessoryView = [self setUpTopAccessoryView];
[self.contentView addSubview:topAccessoryView];
[NSLayoutConstraint activateConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[topAccessoryView]-0-|" options:NSLayoutFormatDirectionLeadingToTrailing metrics:nil views:NSDictionaryOfVariableBindings(topAccessoryView)]];
self.topConstraintForTopView = [NSLayoutConstraint constraintWithItem:topAccessoryView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeTop multiplier:1.0 constant:0];
self.topConstraintForTopView.active = YES;
// Checks if we are using a different object than top labels.
UIView *topView = [self useCustomViewInsteadOfLabels];
self.topView = topView;
@ -115,9 +121,8 @@
}
[self.contentView addSubview:topView];
[NSLayoutConstraint activateConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[topView]-0-|" options:NSLayoutFormatDirectionLeadingToTrailing metrics:nil views:NSDictionaryOfVariableBindings(topView)]];
self.topConstraintForTopView = [NSLayoutConstraint constraintWithItem:topView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeTop multiplier:1.0 constant:0];
self.topConstraintForTopView.active = YES;
[topAccessoryView.bottomAnchor constraintEqualToAnchor:topView.topAnchor constant:0].active = YES;
// Checks if we are using a different object than the bottom buttons.
UIView *bottomView = [self useCustomViewInsteadOfButtons];
self.customBottemView = (bottomView != nil);
@ -266,7 +271,28 @@
if (self.topLabelsView) {
[self.topLabelsView setHeadlineString:[[self mapForTopLabels] stringForKey:KeyTitle] messageString:[[self mapForTopLabels] stringForKey:KeyMessage]];
}
}
- (nullable NSArray *)topAccessoryViews {
return nil;
}
- (UIView *)setUpTopAccessoryView {
UIView *headerAccessoryView = [[UIView alloc] initWithFrame:CGRectZero];
headerAccessoryView.translatesAutoresizingMaskIntoConstraints = NO;
NSArray *accessoryViews = [self topAccessoryViews];
if (accessoryViews.count > 0) {
__block typeof(self) weakSelf = self;
[StackableViewController populateView:headerAccessoryView withUIArray:accessoryViews withSpacingBlock:^UIEdgeInsets(id _Nullable object) {
UIEdgeInsets edgeInsets = [weakSelf spaceAroundUIObject:object];
edgeInsets.left = 0;
edgeInsets.right = 0;
return edgeInsets;
}];
} else {
[NSLayoutConstraint constraintPinView:headerAccessoryView heightConstraint:YES heightConstant:0 widthConstraint:NO widthConstant:0];
}
return headerAccessoryView;
}
- (void)updateViewConstraints {