Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make Navigation Bar stretch behind status bar in xCode 5 / iOS7

I have followed the following tutorial to move my navigation bar down so it is not covered by the status bar in xcode 5/ios7:

Status bar and navigation bar issue in IOS7

But now in iOS7 there is a blank space at the top where the status bar would be and I would like the navigation bar to fill this area too

For instance, Facebook/twittter/Instagram iOS7 apps have the navigation bar background behind the status bar too. How do I achieve this?

Sorry if I'm not being clear but really eager to get this sorted

Thank you!

like image 508
Omar Avatar asked Sep 27 '13 22:09

Omar


1 Answers

You do want to set the barPosition of the UINavigationBar.

You can do this in code:

Let your ViewController conform to protocol UINavigationBarDelegate and implement positionBar: metod. (The protocol that you really need is UIBarPositioningDelegate but UINavigationBarDelegate does extend it.)

@interface SampleViewController () <UINavigationBarDelegate>
@property (weak, nonatomic) IBOutlet UINavigationBar *navigationBar;
@end

@implementation SampleViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _navigationBar.delegate = self;
}

- (UIBarPosition)positionForBar:(id<UIBarPositioning>)bar {
    return UIBarPositionTopAttached;
}
@end

OR in Storyboard:

In the Identity Inspector of UINavigationBar, add a User Defined runtime Attribute with KeyPath = barPosition, Type = Number, and Value = 3:

Add User Defined Runtime Attribute

like image 182
Carien van Zyl Avatar answered Nov 04 '22 13:11

Carien van Zyl