Skip to content

Instantly share code, notes, and snippets.

@3mcd
Last active January 2, 2017 14:27
Show Gist options
  • Save 3mcd/8545807 to your computer and use it in GitHub Desktop.
Save 3mcd/8545807 to your computer and use it in GitHub Desktop.
Place this snippet in the view controller (MainViewController, ChildBrowserViewController, etc) to push the view down 20px to account for the transparent iOS 7 status bar.
@implementation MainViewController
- (void)viewWillAppear:(BOOL)animated
{
// Lower screen 20px on iOS 7
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
CGRect viewBounds = [self.view bounds];
viewBounds.origin.y = 20;
viewBounds.size.height = viewBounds.size.height - 20;
self.webView.frame = viewBounds;
}
[super viewWillAppear:animated];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Lower screen 20px on iOS 7
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
CGRect viewBounds = [self.view bounds];
viewBounds.origin.y = 20;
viewBounds.size.height = viewBounds.size.height - 20; // Push view down 20px to accomidate for iOS 7 status bar
self.webView.frame = viewBounds;
}
// Set bg color to black
self.view.backgroundColor = [UIColor blackColor];
}
// Set text color in status bar to white
-(UIStatusBarStyle)preferredStatusBarStyle{
return UIStatusBarStyleLightContent;
}
@end
@jbailey4
Copy link

Setting the Status Bar background color to a custom color or a color matching your theme
Instead of the default colors you able to define your own using RGB values.
Ex. self.view.backgroundColor = [UIColor colorWithRed:0/255.0f green:8/255.0f blue:36/255.0f alpha:1.0f];
UIColor Code Generator allows you to select your own color while generating the iOS code for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment