4

I want to make an app, which uses a navigationbar, but just for showing the title and some buttons (it is using a vie container). I want the navigation bar to "fusion" with the status bar, like this

Navigation Bar and Status Bar

But when I use a generic view controller and drag a navigation bar in it just looks as this:

Without

Is there a way to do this?

Miterion
  • 152
  • 1
  • 8

6 Answers6

3

I've found a solution for this specific problem. Set the navigation bar's translucent property to NO:

 self.navigationController.navigationBar.translucent = NO;
Shashank Kulshrestha
  • 1,556
  • 17
  • 31
1

UINavigationController will alter the height of its UINavigationBar to either 44 points or 64 points, depending on a rather strange and undocumented set of constraints. If the UINavigationController detects that the top of its view’s frame is visually contiguous with its UIWindow’s top, then it draws its navigation bar with a height of 64 points. If its view’s top is not contiguous with the UIWindow’s top (even if off by only one point), then it draws its navigation bar in the “traditional” way with a height of 44 points. This logic is performed by UINavigationController even if it is several children down inside the view controller hierarchy of your application. There is no way to prevent this behavior.

Full explanation here.

Community
  • 1
  • 1
jaredsinclair
  • 12,687
  • 5
  • 35
  • 56
  • I do not want to use an UINavigation Controller, just an generic view controller. Is it possible to do it there too? – Miterion Sep 18 '13 at 18:10
0

Not sure whether this will fix your issue, but you can try what i did.

I had the same problem in viewcontroller's right side menu "Simulated Metics" > Top Bar > "Opaque Navigation Bar"

therealvj
  • 51
  • 4
0
  • viewcontroller.h file in create iboutlet of the navigation bar

    @property (weak, nonatomic) IBOutlet UINavigationBar *navBar;

  • You can do as followings in viewDidLoad

    UIView *addStatusBar = [[UIView alloc] init];

    //draw status bar with width of device addStatusBar.frame = CGRectMake(0, -20, self.view.frame.size.width, 20);

    //set the background colour to status bar

    addStatusBar.backgroundColor = [UIColor colorWithRed:24.0/255. green:24/255. blue:24.0/255. alpha:1];

    [self.view addSubview:addStatusBar];

    // add your status bar to your UINavigationBar *navBar which declared in your file .h [self.navBar addSubview:addStatusBar];

Xuan Bui
  • 1
  • 1
0
navigationController.navigationBar.clipsToBounds = YES;

In order for UINavigationBar to extend its background under status bar its clipsToBounds must be set to NO (which is the default). Make sure you do not mock around with it.

Solution simple as:-

navigationController.navigationBar.clipsToBounds = NO;
Peter Haddad
  • 78,874
  • 25
  • 140
  • 134
0

Swift 5

navigationController?.navigationBar.isTranslucent = false
Wissa
  • 1,444
  • 20
  • 24