Created
October 22, 2014 11:34
-
-
Save mlabraca/11ca48726b4c91a62957 to your computer and use it in GitHub Desktop.
Add background to StatusBar in AppDelegate didFinishLaunchingWithOptions
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
//Create the background | |
UIView* statusBg = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.window.frame.size.width, 20)]; | |
//statusBg.backgroundColor = [UIColor colorWithWhite:1 alpha:.7]; | |
statusBg.backgroundColor = [UIColor whiteColor]; | |
//Add the view behind the status bar | |
[self.window.rootViewController.view addSubview:statusBg]; | |
//set the constraints to auto-resize | |
statusBg.translatesAutoresizingMaskIntoConstraints = NO; | |
[statusBg.superview addConstraint:[NSLayoutConstraint constraintWithItem:statusBg attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:statusBg.superview attribute:NSLayoutAttributeTop multiplier:1.0 constant:0.0]]; | |
[statusBg.superview addConstraint:[NSLayoutConstraint constraintWithItem:statusBg attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:statusBg.superview attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0.0]]; | |
[statusBg.superview addConstraint:[NSLayoutConstraint constraintWithItem:statusBg attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:statusBg.superview attribute:NSLayoutAttributeRight multiplier:1.0 constant:0.0]]; | |
[statusBg.superview addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[statusBg(==20)]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(statusBg)]]; | |
[statusBg.superview setNeedsUpdateConstraints]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment