Search code examples
iosxcodenavigationuinavigationbarextending

UINavigationBar doesn't expand or extend to the device width


The navigation bar doesn't seem to scale to different device widths. It just works on my 5s, but in the simulators, it appears as shown below.

I've created a few apps before, and I never faced this problem. Any ideas as to what I'm doing wrong in this project?

Notice the background change between the navigation bar and the view background

Similarly, for the iPad Air


Solution

  • I had added a category to keep the height of the navigation bar constant across landscape and portrait modes. This was my mistake. Removing it, solved this issue.

    FYI, this was the category:

    #import "UINavigationBar+DiscoverCustomHeight.h"
    
    @implementation UINavigationBar (DiscoverCustomHeight)
    - (CGSize)sizeThatFits:(CGSize)size
    {
        CGSize newSize = CGSizeMake(self.frame.size.width,44);
        return newSize;
    }
    @end