Skip to content

Instantly share code, notes, and snippets.

@bobspryn
Created March 28, 2014 19:20
Show Gist options
  • Select an option

  • Save bobspryn/9840882 to your computer and use it in GitHub Desktop.

Select an option

Save bobspryn/9840882 to your computer and use it in GitHub Desktop.
- (void) setupButtons {
NSMutableArray *buttons = [@[] mutableCopy];
for (NSUInteger i = 0; i < TCInviteSectionFacebook; i++) {
TCInviteFriendsTabButton *button = [[TCInviteFriendsTabButton alloc] init];
button.translatesAutoresizingMaskIntoConstraints = NO;
button.viewModel = self.viewModel;
button.section = i;
[buttons addObject:button];
[self.view addSubview:button];
}
self.buttons = [buttons copy];
}
- (void) updateViewConstraints {
if (!self.mainViewConstraintsSetup) {
for (UIView *button in self.buttons) {
NSInteger indexOfObject = [self.buttons indexOfObject:button];
if (indexOfObject == 0) {
[button pinEdge:NSLayoutAttributeLeft toEdge:NSLayoutAttributeLeft ofItem:self.view];
} else {
UIView *previousButton = [self.buttons objectAtIndex:indexOfObject - 1];
[button pinEdge:NSLayoutAttributeLeft toEdge:NSLayoutAttributeRight ofItem:previousButton];
[button pinAttribute:NSLayoutAttributeWidth toSameAttributeOfItem:previousButton];
}
if (indexOfObject == TCInviteSectionFacebook - 1) {
[button pinEdge:NSLayoutAttributeRight toEdge:NSLayoutAttributeRight ofItem:self.view];
}
[button pinEdge:NSLayoutAttributeTop toEdge:NSLayoutAttributeBottom ofItem:self.topLayoutGuide];
[button constrainToHeight:60];
}
[self.selectedTabIndicator constrainToHeight:2];
[self.selectedTabIndicator pinAttribute:NSLayoutAttributeWidth toSameAttributeOfItem:self.buttons[0]];
[self.selectedTabIndicator pinEdge:NSLayoutAttributeBottom toEdge:NSLayoutAttributeBottom ofItem:self.buttons[0]];
self.mainViewConstraintsSetup = YES;
}
if (!self.leftIndicatorConstraint) {
self.leftIndicatorConstraint = [self.selectedTabIndicator pinEdge:NSLayoutAttributeLeft toEdge:NSLayoutAttributeLeft ofItem:self.buttons[self.viewModel.currentSection]];
}
if (!self.childViewControllerConstraintsSetup) {
UIView *childView = self.currentViewController.view;
[childView pinToSuperviewEdges:(JRTViewPinLeftEdge|JRTViewPinBottomEdge|JRTViewPinRightEdge) inset:0];
[childView pinEdge:NSLayoutAttributeTop toEdge:NSLayoutAttributeBottom ofItem:self.buttons[0]];
self.childViewControllerConstraintsSetup = YES;
}
[super updateViewConstraints];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment