23

Have a problem with layouts.

Here is how it looks right on iOS6:

enter image description here

Here is how looks on iOS7:

enter image description here

But it's ok. And like described in Apple's iOS7 TransitionGuide I wrote one more stroke in - (void)viewDidLoad

        self.edgesForExtendedLayout = UIRectEdgeNone;

And it now it's look like this:

enter image description here

Any suggestions? What can be wrong with my layouts? I want solid blue UINavigationBar. And have no idea, why the top of this is transparent. Have any ideas, why it looks so strange? How can I fix this?

skywinder
  • 21,291
  • 15
  • 93
  • 123

3 Answers3

31

Try navigationBar.translucent = NO;

It is YES by default.

From the UINavigationBar documentation:

New behavior on iOS 7. Default is YES. You may force an opaque background by setting the property to NO. If the navigation bar has a custom background image, the default is inferred from the alpha values of the image—YES if it has any pixel with alpha < 1.0 If you send setTranslucent:YES to a bar with an opaque custom background image it will apply a system opacity less than 1.0 to the image. If you send setTranslucent:NO to a bar with a translucent custom background image it will provide an opaque background for the image using the bar's barTintColor if defined, or black for UIBarStyleBlack or white for UIBarStyleDefault if barTintColor is nil.

vqdave
  • 2,361
  • 1
  • 18
  • 36
Tarek Hallak
  • 18,422
  • 7
  • 59
  • 68
  • Yes, thank you! It's partly solve problem, but now colors looks a quite different. I hope, that exist way to leave navigationBar translucent, but fix layouts of tableView. What do you think about? – skywinder Sep 13 '13 at 23:17
  • Might include that this can't be done in `-viewDidLoad:`. I couldn't figure out for the life of me why it wouldn't work and that was why. Be sure to put it in `-viewWillAppear:` instead. – Dean Kelly Jul 08 '14 at 22:54
8

Add this line to your 'view will appear' method (if it is not there, add it by typing:

- (void)viewWillAppear:(BOOL)animated
{

    [super viewWillAppear:animate];

}

)

Then, at the bottom of viewWillAppear, underneath the [self viewWillAppear:] line, add this code:

if([self respondsToSelector:@selector(edgesForExtendedLayout)])
    [self setEdgesForExtendedLayout:UIRectEdgeBottom];

This will make the top bar (nav bar) go opaque. In iOS 7, Obj-C now responds differently to whether or not the nav bar has been set to opaque, and this is a good way to gaurentee it works in both iOS 6 and 7 (there are some problems doing just:

navigationBar.translucent = NO;

)

Hope this helps, I had the same problem when I converted an app to iOS 7 and it took ages to find a solution!

Jack Solomon
  • 880
  • 1
  • 8
  • 19
  • 1
    I believe you mean `[super viewWillAppear:animate]`. Otherwise that's an infinite loop. – devios1 Dec 05 '13 at 19:25
  • This also fixed an issue I had where my app's behavior was different between the device and the simulator -- only the device needed a 64pt offset for the status/nav bar. Adding the setEdges... code worked like a charm. Thanks a bunch. – weienw Jan 22 '14 at 17:23
4

In IOS7 UINavigationBar style is Translucent by default so it will hide view Content Underneath, to show your content Under UInavigation bar write down following snippet in given method.

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    if([self respondsToSelector:@selector(edgesForExtendedLayout)])
        [self setEdgesForExtendedLayout:UIRectEdgeBottom];
}
Dipen Panchasara
  • 13,480
  • 5
  • 47
  • 57