Not sure if it works in all cases, but here is a starting point.
I noticed that UINavigationBar
height could be changed via autolayout constraints. By default bar's autoresizing mask is translated into constraints. I turned it off and added width and height constraints manually. Width constraint depends on orientation and should be changed when orientation transition occurs. All changes are performed in UINavigationController
subclass.
@interface NavigationController ()
@property (strong, nonatomic) NSLayoutConstraint *widthConstraint;
@end
@implementation NavigationController
- (void)viewDidLoad
{
[super viewDidLoad];
UIView *navbar = self.navigationBar;
navbar.translatesAutoresizingMaskIntoConstraints = NO;
[navbar addConstraints:[NSLayoutConstraint
constraintsWithVisualFormat:@"V:[navbar(80)]" // custom height
options:0
metrics:nil
views:NSDictionaryOfVariableBindings(navbar)]];
[navbar addConstraints:[NSLayoutConstraint
constraintsWithVisualFormat:@"[navbar(320)]"
options:0
metrics:nil
views:NSDictionaryOfVariableBindings(navbar)]];
self.widthConstraint = navbar.constraints[1]; // width is the 2nd constraint
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
CGSize size = [UIScreen mainScreen].bounds.size;
self.widthConstraint.constant =
UIInterfaceOrientationIsLandscape(toInterfaceOrientation)
? size.height
: size.width;
[UIView animateWithDuration:duration animations:^{
[self.navigationBar layoutIfNeeded];
}];
}
@end
For adjusting back button use custom back button image and position an icon within image as you wish. Use [UINavigationBar appearance]
to set custom back button.
[[UINavigationBar appearance] setBackIndicatorImage:[UIImage imageNamed:@"IconBack"]];
[[UINavigationBar appearance] setBackIndicatorTransitionMaskImage:[UIImage new]];
For adjusting titles use corresponding methods of UINavigationBar
and UIBarButtonItem
appearances.
[[UINavigationBar appearance] setTitleVerticalPositionAdjustment:10 forBarMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -10) forBarMetrics:UIBarMetricsDefault];