Last active
December 26, 2015 13:29
-
-
Save jsai/7158977 to your computer and use it in GitHub Desktop.
Bar button item padding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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, | |
LIButtonNavPositionLeft, | |
LIButtonNavPositionRight | |
} LIButtonNavPosition; | |
@interface LIButton : UIButton | |
/*! Position of button when used as Custom View in navigation bar. | |
*/ | |
@property (nonatomic) LIButtonNavPosition positionInNavBar; | |
@end | |
@implementation LIButton | |
/*! Override and return insets based on location in navigation bar. | |
*/ | |
- (UIEdgeInsets)alignmentRectInsets { | |
if (LI_IS_IOS7_RUNTIME) { | |
switch (self.positionInNavBar) { | |
case LIButtonNavPositionLeft: | |
return UIEdgeInsetsMake(0.0, 12.0, 0.0, 0.0); | |
break; | |
case LIButtonNavPositionRight: | |
return UIEdgeInsetsMake(0.0, 0.0, 0.0, 12.0); | |
break; | |
default: | |
return UIEdgeInsetsZero; | |
break; | |
} | |
} | |
return UIEdgeInsetsZero; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment