Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save marcuswestin/7799473 to your computer and use it in GitHub Desktop.
Save marcuswestin/7799473 to your computer and use it in GitHub Desktop.
Multiple UINavigationBar buttons with corrected positioning.
UIButton* left = [UIButton.styler.h(44) onTap:^(UIEvent *event) {
[Overlay showMessage:@"Me"];
}];
[UIImageView.appendTo(left).image([UIImage imageNamed:@"img/Me"]).xy(-10, 2) render];
UIButton* right = [UIButton.styler.wh(88,44) render];
CGFloat offsetRight = 26;
UIView* compose = [UIImageView.appendTo(right).image([UIImage imageNamed:@"img/Compose"]).fromRight(6) render];
UIView* search = [UIImageView.appendTo(right).image([UIImage imageNamed:@"img/Search"]).leftOf(compose, 0) render];
[right onTap:^(UIEvent *event) {
UITouch* touch = [event.allTouches anyObject];
CGPoint location = [touch locationInView:right];
if (location.x >= search.x2) {
[self pushViewController:[ContactsViewController new]];
} else {
[Overlay showMessage:@"Search"];
}
}];
// Fix positioning
left.width = 46;
right.width = 70;
[self.navigationItem setLeftBarButtonItem:[[UIBarButtonItem alloc] initWithCustomView:left]];
[self.navigationItem setRightBarButtonItem:[[UIBarButtonItem alloc] initWithCustomView:right]];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment