Miterion
Miterion

Reputation: 152

Letting the Navigationbar overlap the Statusbar in iOS 7

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?

Upvotes: 4

Views: 3663

Answers (6)

Wissa
Wissa

Reputation: 1592

Swift 5

navigationController?.navigationBar.isTranslucent = false

Upvotes: 0

Shubham Nigam
Shubham Nigam

Reputation: 1

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;

Upvotes: 0

Xuan Bui
Xuan Bui

Reputation: 1

  • 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];

Upvotes: 0

jaredsinclair
jaredsinclair

Reputation: 12687

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.

Upvotes: 1

therealvj
therealvj

Reputation: 51

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"

Upvotes: 0

Shashank Kulshrestha
Shashank Kulshrestha

Reputation: 1556

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

 self.navigationController.navigationBar.translucent = NO;

Upvotes: 3

Related Questions