Note that there are some explanatory texts on larger screens.

plurals
  1. POCustom titleView in UINavigationItem doesn't adjust height if offscreen during rotation
    primarykey
    data
    text
    <p>I have a custom titleView for a <code>UINavigationItem</code> with the <code>autoresizeMask</code> set to adjust the width and height of the view. If I rotate the device while it is visible, the height is automatically adjusted for the shorter landscape nav bar. However, if I push a new view controller, rotate the device, and then come back to the one with the custom titleView, it doesn't recognize the change in height. For now I've added the following code to the <code>viewWillAppear:</code> method</p> <pre><code>- (void) viewWillAppear:(BOOL)animated { CGRect frame = self.titleButton.frame; if (UIInterfaceOrientationIsPortrait(self.interfaceOrientation)) { frame.size = CGSizeMake(self.navigationController.navigationBar.frame.size.width - 150.0f, 44.0f); } else { frame.size = CGSizeMake(self.navigationController.navigationBar.frame.size.width - 150.0f, 32.0f); } self.titleButton.frame = frame; ... } </code></pre> <p>This fixes the issue, but I'm wondering if I'm missing some property to get things adjusting on their own properly. The custom view is a UIButton:</p> <pre><code>titleButton = [UIButton buttonWithType:UIButtonTypeCustom]; [titleButton setFrame:CGRectMake(0, 0, self.navigationController.navigationBar.frame.size.width - 150.0f, 44.0f)]; [[titleButton titleLabel] setFont:[UIFont boldSystemFontOfSize:18]]; [titleButton setBackgroundImage:navbarButtonImage forState:UIControlStateNormal]; [titleButton setBackgroundImage:navbarButtonPressedImage forState:UIControlStateSelected]; [titleButton setBackgroundImage:navbarButtonPressedImage forState:UIControlStateHighlighted]; titleButton.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; titleButton.autoresizesSubviews = YES; </code></pre> <p>Is there a better way to setup this view?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload