Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 7 UINavigationBar - UIView layout issue

Tags:

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?

like image 613
skywinder Avatar asked Sep 13 '13 14:09

skywinder


3 Answers

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.

like image 128
Tarek Hallak Avatar answered Oct 01 '22 12:10

Tarek Hallak


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!

like image 42
Jack Solomon Avatar answered Oct 01 '22 11:10

Jack Solomon


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];
}
like image 40
Dipen Panchasara Avatar answered Oct 01 '22 11:10

Dipen Panchasara