In my application, I\'d like to have the navigation bar display a title and subtitle.
To that extent, I added the following code to my view controller:
Make the titleView
and subtitleView
labels into properties of the view controller, so that you can access them from any method. Then, on rotation of the view controller, resize the labels:
- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[self adjustLabelsForOrientation:toInterfaceOrientation];
}
- (void) adjustLabelsForOrientation:(UIInterfaceOrientation)orientation {
if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) {
titleView.font = [UIFont boldSystemFontOfSize:16];
subtitleView.font = [UIFont boldSystemFontOfSize:11];
}
else if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
titleView.font = [UIFont boldSystemFontOfSize:20];
subtitleView.font = [UIFont boldSystemFontOfSize:13];
}
}
Instead of this authoresizing mask
_headerTitleSubtitleView.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin |
UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleTopMargin |
UIViewAutoresizingFlexibleBottomMargin);
you should use
_headerTitleSubtitleView.autoresizingMask = UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleHeight;
titleView.autoresizingMask = UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleHeight;
subtitleView.autoresizingMask = UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleHeight;