Skip to content

Instantly share code, notes, and snippets.

@sdpjswl
Last active July 29, 2016 06:24
Show Gist options
  • Save sdpjswl/4e341c5651f84e5ae208953a473ee22d to your computer and use it in GitHub Desktop.
Save sdpjswl/4e341c5651f84e5ae208953a473ee22d to your computer and use it in GitHub Desktop.
Set default navigation bar and back button for app
// hide back button text
// fixes navigation title position
http://stackoverflow.com/questions/23853617/uinavigationbar-hide-back-button-text
- (void)setupNavigationBar
{
[UINavigationBar appearance].barStyle = UIBarStyleDefault;
[UINavigationBar appearance].barTintColor = [UIColor blueColor];
[UINavigationBar appearance].translucent = NO;
NSDictionary *attributes = @{NSForegroundColorAttributeName: [UIColor whiteColor],
NSFontAttributeName: [UIFont systemFontWithSize:17.0f]};
[UINavigationBar appearance].titleTextAttributes = attributes;
}
- (void)setupBackButton
{
UIImage *backArrow = [[UIImage imageNamed:@"back"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
[[UINavigationBar appearance] setBackIndicatorImage:backArrow];
[[UINavigationBar appearance] setBackIndicatorTransitionMaskImage:backArrow];
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0.0f, -60.0f) forBarMetrics:UIBarMetricsDefault];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment