Skip to content

Instantly share code, notes, and snippets.

Last active December 26, 2015 13:29
Show Gist options
  • Save jsai/7158977 to your computer and use it in GitHub Desktop.
Save jsai/7158977 to your computer and use it in GitHub Desktop.
Bar button item padding
- (void)setupBackButtonWithSelector:(SEL)selector {
// create a custom button
LIButton *backButton = [LIButton buttonWithType:UIButtonTypeCustom];
backButton.positionInNavBar = LIButtonNavPositionLeft;
// more back button setup
// add back button to navigation bar
UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
self.navigationItem.leftBarButtonItem = backItem;
/*! Position in navigation bar
typedef enum LIButtonNavPosition {
LIButtonNavPositionNone = 0,
} LIButtonNavPosition;
@interface LIButton : UIButton
/*! Position of button when used as Custom View in navigation bar.
@property (nonatomic) LIButtonNavPosition positionInNavBar;
@implementation LIButton
/*! Override and return insets based on location in navigation bar.
- (UIEdgeInsets)alignmentRectInsets {
switch (self.positionInNavBar) {
case LIButtonNavPositionLeft:
return UIEdgeInsetsMake(0.0, 12.0, 0.0, 0.0);
case LIButtonNavPositionRight:
return UIEdgeInsetsMake(0.0, 0.0, 0.0, 12.0);
return UIEdgeInsetsZero;
return UIEdgeInsetsZero;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment