top accessory in tableview controller
This commit is contained in:
parent
f1b8a61e04
commit
627114ded8
@ -71,4 +71,6 @@
|
||||
- (BOOL)bottomViewOutsideOfScroll;
|
||||
//override for setting attributed headline and message
|
||||
-(void)setHeadlineAndMessage;
|
||||
- (nullable NSArray *)topAccessoryViews;
|
||||
|
||||
@end
|
||||
|
||||
@ -70,6 +70,27 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (nullable NSArray *)topAccessoryViews {
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (nullable UIView *)setUpTopAccessoryView {
|
||||
NSArray *accessoryViews = [self topAccessoryViews];
|
||||
if (accessoryViews.count > 0) {
|
||||
UIView *headerAccessoryView = [[UIView alloc] initWithFrame:CGRectZero];
|
||||
headerAccessoryView.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
|
||||
__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;
|
||||
}];
|
||||
return headerAccessoryView;
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void)newDataBuildScreen {
|
||||
[super newDataBuildScreen];
|
||||
@ -92,10 +113,10 @@
|
||||
[self setHeadlineAndMessage];
|
||||
self.topView = topLabelsView;
|
||||
}
|
||||
|
||||
|
||||
// Setup accessory view.
|
||||
[self setUpHeaderAccessoryView];
|
||||
|
||||
|
||||
// add top view to table header
|
||||
if (self.topView) {
|
||||
self.topView.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
@ -253,16 +274,34 @@
|
||||
UIView *headerAccessoryView = self.headerAccessoryView;
|
||||
[header addSubview:topView];
|
||||
[header addSubview:headerAccessoryView];
|
||||
|
||||
// Sets up the constraints
|
||||
if (headerAccessoryView) {
|
||||
[NSLayoutConstraint activateConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[topView]-0-[headerAccessoryView]" options:NSLayoutFormatDirectionLeadingToTrailing metrics:nil views:NSDictionaryOfVariableBindings(topView,headerAccessoryView)]];
|
||||
[NSLayoutConstraint constraintPinSubview:topView pinTop:YES topConstant:0 pinBottom:NO bottomConstant:0 pinLeft:YES leftConstant:0 pinRight:YES rightConstant:0];
|
||||
self.topViewBottomConstraint = [[NSLayoutConstraint constraintPinSubview:headerAccessoryView pinTop:NO topConstant:0 pinBottom:YES bottomConstant:[[self spaceAboveBetweenView] floatValue] pinLeft:YES leftConstant:0 pinRight:YES rightConstant:0] objectForKey:ConstraintBot ofType:[NSLayoutConstraint class]];
|
||||
}
|
||||
else {
|
||||
self.topViewBottomConstraint = [[NSLayoutConstraint constraintPinSubview:topView pinTop:YES topConstant:0 pinBottom:YES bottomConstant:[[self spaceAboveBetweenView] floatValue] pinLeft:YES leftConstant:0 pinRight:YES rightConstant:0] objectForKey:ConstraintBot ofType:[NSLayoutConstraint class]];
|
||||
}
|
||||
|
||||
UIView *topAccessoryView = [self setUpTopAccessoryView];
|
||||
if (topAccessoryView) {
|
||||
[header addSubview:topAccessoryView];
|
||||
[NSLayoutConstraint constraintPinSubview:topAccessoryView pinTop:YES pinBottom:NO pinLeft:YES pinRight:YES];
|
||||
[topAccessoryView.bottomAnchor constraintEqualToAnchor:topView.topAnchor constant:0].active = YES;
|
||||
|
||||
// Sets up the constraints
|
||||
if (headerAccessoryView) {
|
||||
[NSLayoutConstraint activateConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[topView]-0-[headerAccessoryView]" options:NSLayoutFormatDirectionLeadingToTrailing metrics:nil views:NSDictionaryOfVariableBindings(topView,headerAccessoryView)]];
|
||||
[NSLayoutConstraint constraintPinSubview:topView pinTop:NO topConstant:0 pinBottom:NO bottomConstant:0 pinLeft:YES leftConstant:0 pinRight:YES rightConstant:0];
|
||||
self.topViewBottomConstraint = [[NSLayoutConstraint constraintPinSubview:headerAccessoryView pinTop:NO topConstant:0 pinBottom:YES bottomConstant:[[self spaceAboveBetweenView] floatValue] pinLeft:YES leftConstant:0 pinRight:YES rightConstant:0] objectForKey:ConstraintBot ofType:[NSLayoutConstraint class]];
|
||||
}
|
||||
else {
|
||||
self.topViewBottomConstraint = [[NSLayoutConstraint constraintPinSubview:topView pinTop:NO topConstant:0 pinBottom:YES bottomConstant:[[self spaceAboveBetweenView] floatValue] pinLeft:YES leftConstant:0 pinRight:YES rightConstant:0] objectForKey:ConstraintBot ofType:[NSLayoutConstraint class]];
|
||||
}
|
||||
} else {
|
||||
// Sets up the constraints
|
||||
if (headerAccessoryView) {
|
||||
[NSLayoutConstraint activateConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[topView]-0-[headerAccessoryView]" options:NSLayoutFormatDirectionLeadingToTrailing metrics:nil views:NSDictionaryOfVariableBindings(topView,headerAccessoryView)]];
|
||||
[NSLayoutConstraint constraintPinSubview:topView pinTop:YES topConstant:0 pinBottom:NO bottomConstant:0 pinLeft:YES leftConstant:0 pinRight:YES rightConstant:0];
|
||||
self.topViewBottomConstraint = [[NSLayoutConstraint constraintPinSubview:headerAccessoryView pinTop:NO topConstant:0 pinBottom:YES bottomConstant:[[self spaceAboveBetweenView] floatValue] pinLeft:YES leftConstant:0 pinRight:YES rightConstant:0] objectForKey:ConstraintBot ofType:[NSLayoutConstraint class]];
|
||||
}
|
||||
else {
|
||||
self.topViewBottomConstraint = [[NSLayoutConstraint constraintPinSubview:topView pinTop:YES topConstant:0 pinBottom:YES bottomConstant:[[self spaceAboveBetweenView] floatValue] pinLeft:YES leftConstant:0 pinRight:YES rightConstant:0] objectForKey:ConstraintBot ofType:[NSLayoutConstraint class]];
|
||||
}
|
||||
}
|
||||
|
||||
self.headerView = header;
|
||||
}
|
||||
|
||||
@ -281,6 +320,7 @@
|
||||
self.footerView = footer;
|
||||
}
|
||||
|
||||
|
||||
- (void)showHeader {
|
||||
|
||||
if (self.headerView) {
|
||||
|
||||
@ -102,12 +102,6 @@
|
||||
[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;
|
||||
@ -121,8 +115,18 @@
|
||||
}
|
||||
[self.contentView addSubview:topView];
|
||||
[NSLayoutConstraint activateConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[topView]-0-|" options:NSLayoutFormatDirectionLeadingToTrailing metrics:nil views:NSDictionaryOfVariableBindings(topView)]];
|
||||
[topAccessoryView.bottomAnchor constraintEqualToAnchor:topView.topAnchor constant:0].active = YES;
|
||||
|
||||
UIView *topAccessoryView = [self setUpTopAccessoryView];
|
||||
if (topAccessoryView) {
|
||||
[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];
|
||||
[topAccessoryView.bottomAnchor constraintEqualToAnchor:topView.topAnchor constant:0].active = YES;
|
||||
} else {
|
||||
self.topConstraintForTopView = [NSLayoutConstraint constraintWithItem:topView 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 the bottom buttons.
|
||||
UIView *bottomView = [self useCustomViewInsteadOfButtons];
|
||||
self.customBottemView = (bottomView != nil);
|
||||
@ -277,11 +281,12 @@
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (UIView *)setUpTopAccessoryView {
|
||||
UIView *headerAccessoryView = [[UIView alloc] initWithFrame:CGRectZero];
|
||||
headerAccessoryView.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
- (nullable UIView *)setUpTopAccessoryView {
|
||||
NSArray *accessoryViews = [self topAccessoryViews];
|
||||
if (accessoryViews.count > 0) {
|
||||
UIView *headerAccessoryView = [[UIView alloc] initWithFrame:CGRectZero];
|
||||
headerAccessoryView.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
|
||||
__block typeof(self) weakSelf = self;
|
||||
[StackableViewController populateView:headerAccessoryView withUIArray:accessoryViews withSpacingBlock:^UIEdgeInsets(id _Nullable object) {
|
||||
UIEdgeInsets edgeInsets = [weakSelf spaceAroundUIObject:object];
|
||||
@ -289,10 +294,9 @@
|
||||
edgeInsets.right = 0;
|
||||
return edgeInsets;
|
||||
}];
|
||||
} else {
|
||||
[NSLayoutConstraint constraintPinView:headerAccessoryView heightConstraint:YES heightConstant:0 widthConstraint:NO widthConstant:0];
|
||||
return headerAccessoryView;
|
||||
}
|
||||
return headerAccessoryView;
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void)updateViewConstraints {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user