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 #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 // Allow you to add any additional ui before buildViewsBetweenLabelsAndButtons gets called. Can use this to set the topBetweenEdgeView or bottomBetweenEdgeView
- (void)buildInAdditionalViewsBeforeCenteredContent; - (void)buildInAdditionalViewsBeforeCenteredContent;
// For subclassing. Should return all the views that will be in between labels and buttons. Override standardSpaceAroundUIObject to handle spacing. // For subclassing. Should return all the views that will be in between labels and buttons. Override standardSpaceAroundUIObject to handle spacing.

View File

@ -102,6 +102,12 @@
[self.viewOutOfScroll removeFromSuperview]; [self.viewOutOfScroll removeFromSuperview];
[StackableViewController removeUIViews:[self.contentView subviews]]; [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. // Checks if we are using a different object than top labels.
UIView *topView = [self useCustomViewInsteadOfLabels]; UIView *topView = [self useCustomViewInsteadOfLabels];
self.topView = topView; self.topView = topView;
@ -115,8 +121,7 @@
} }
[self.contentView addSubview:topView]; [self.contentView addSubview:topView];
[NSLayoutConstraint activateConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[topView]-0-|" options:NSLayoutFormatDirectionLeadingToTrailing metrics:nil views:NSDictionaryOfVariableBindings(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]; [topAccessoryView.bottomAnchor constraintEqualToAnchor:topView.topAnchor constant:0].active = YES;
self.topConstraintForTopView.active = YES;
// Checks if we are using a different object than the bottom buttons. // Checks if we are using a different object than the bottom buttons.
UIView *bottomView = [self useCustomViewInsteadOfButtons]; UIView *bottomView = [self useCustomViewInsteadOfButtons];
@ -266,7 +271,28 @@
if (self.topLabelsView) { if (self.topLabelsView) {
[self.topLabelsView setHeadlineString:[[self mapForTopLabels] stringForKey:KeyTitle] messageString:[[self mapForTopLabels] stringForKey:KeyMessage]]; [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 { - (void)updateViewConstraints {