Last active
January 2, 2017 14:27
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.