0

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

judepereira
  • 1,239
  • 2
  • 17
  • 24
  • Are you using auto layout? If not you should :) – Daniel Galasko Jul 05 '15 at 07:45
  • I am very much using auto layout. It's the most awesome thing on the planet :) – judepereira Jul 05 '15 at 07:46
  • Are you using a custom navigation bar added to a view of a navigation controllers bar? – Daniel Galasko Jul 05 '15 at 07:47
  • No, I've added it in the storyboard. – judepereira Jul 05 '15 at 07:48
  • Interesting decision. Then you probably haven't set the leading and trailing constraints for the bar. But if you embed it in a navigation controller you will get a bar for free:) – Daniel Galasko Jul 05 '15 at 07:49
  • My root view controller is a navigation controller – judepereira Jul 05 '15 at 07:50
  • As I said. Please describe your constraints in your question. I'm not sure what the context of this controller even is and why you have added a bar to it. I find it's always easier to simply use the navigation controllers bar. Your constraints should look like this http://stackoverflow.com/a/27900842/1652402 – Daniel Galasko Jul 05 '15 at 07:52
  • I just noticed that I'm using a category that tries to set the navigation bar's height. However, the widget is untouched. If I remove this category, it all works well. The only line in my category is CGSize newSize = CGSizeMake(self.frame.size.width,44) inside sizeThatFits:. Why is this causing the width to suffer? – judepereira Jul 05 '15 at 07:53
  • I can't tell you without any code. But you definitely shouldn't call sizeThatFits on a bar. Again, auto layout solves this – Daniel Galasko Jul 05 '15 at 07:54
  • Just figured that I don't need this category anymore. I had added it to set the height constant across landscape and portrait, but I don't need it so anymore. Thanks for all your help! – judepereira Jul 05 '15 at 07:57

1 Answers1

2

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
judepereira
  • 1,239
  • 2
  • 17
  • 24