Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set UINavigationBar height like in iOS 7 calendar app

I need a NavigationBar like in the calendar in iOS 7.

I have noticed that the NavigationBar does not have any blur behind it.

Calendar app iOS7

when going back from one detail view. It's just the "main" NavigationBar that is "normal".

Calendar app iOS7

Anyone have any idea how to do this?

I have tried to do this:

[self.navigationController.navigationBar setFrame:CGRectMake(0, 0, 320, 88)];

But this would move the title and the buttons down 44px.

I have another idea to add another navigation bar under the navigationController.navigationBar, but then I have a line under the first navigation bar. Anyone knows how to remove this?

Thanks!

like image 696
Gustaf Rosenblad Avatar asked Sep 20 '13 20:09

Gustaf Rosenblad


1 Answers

I fixed it!

I placed a other NavigationBar under the "main" NavigationBar. Removed the "main" NavigationBars shadow line.

Remove the NavigationBar translucent and set the background color to 97% white. (it's standard). If translucent is YES it would look strange when content is behind .

[self.navigationController.navigationBar setTranslucent:NO];
[self.navigationController.navigationBar setBarTintColor:[UIColor colorWithWhite:0.97 alpha:1]];
[NavigationBarExtension setTranslucent:NO];
[NavigationBarExtension setBarTintColor:[UIColor colorWithWhite:0.97 alpha:1]];

Code to remove the line (do this in viewWillAppear: because if you push a other view controller the line must come back)

- (void)viewWillAppear:(BOOL)animated {
    for (UIView *view in self.navigationController.navigationBar.subviews) {
        if ([view isKindOfClass:NSClassFromString(@"_UINavigationBarBackground")]) {
            for (UIView *view2 in view.subviews) {
                if ([view2 isKindOfClass:[UIImageView class]] && view2.frame.size.height < 1) {
                    [view2 setHidden:YES];
                    break;
                }
            }
        }
    }
}

Code to show the line when pushing a other view controller:

- (void)viewWillAppear:(BOOL)animated {
    for (UIView *view in self.navigationController.navigationBar.subviews) {
        if ([view isKindOfClass:NSClassFromString(@"_UINavigationBarBackground")]) {
            for (UIView *view2 in view.subviews) {
                if ([view2 isKindOfClass:[UIImageView class]] && view2.frame.size.height < 1) {
                    [view2 setHidden:NO];
                    break;
                }
            }
        }
    }
}
like image 171
Gustaf Rosenblad Avatar answered Oct 21 '22 06:10

Gustaf Rosenblad