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