Opaque white status bar in iOS7 - ios

First off, I'm aware that the two well know ways of modifying the status bar are
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
and
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
However, with the default style, the status bar has black text with a clear (or translucent white - I can't tell) background. A view in my application slides up at certain points, and it is viewable through the status bar. Is there a way to make the status bar background an opaque white color?
Thanks

I solved this by creating a Base View Controller that each VC inherits from, and adding the following to viewDidLoad:
//Make status bar opaque
CGRect blocker = CGRectMake(0, 0, self.view.frame.size.width, 20);
ColoredLineSegment *blockerView = [[ColoredLineSegment alloc] initWithFrame:blocker]; //ColoredLineSegment is just a colored in rect
blockerView.color = [UIColor whiteColor];
[[[[UIApplication sharedApplication] windows] objectAtIndex:0] addSubview:blockerView];
[[[[UIApplication sharedApplication] windows] objectAtIndex:0] bringSubviewToFront:blockerView];

Try this in AppDelegate.m :
[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:255.0/255 green:255.0/255 blue:255.0/255 alpha:1.0]];
It should work !

Related

Is it possible to obtain a Navigation Bars current "barTintColor"?

I am trying to create a unit test for my app that checks the color of the Navigation Bar and compares it to the User Defaults saved for the theme color within the app.
I can't seem to find a way to access the bars current color. Is this even possible?
- (void) testColorThemeNavigationBar {
UINavigationBar *navigationBar = [[UINavigationBar alloc] init];
MSMColorManager *manager = [[MSMColorManager alloc]init];
navigationBar = [manager getNavBar];
UIColor *navBarColor = [[UIColor alloc]init];
UIColor *currentThemeColor = [[UIColor alloc] init];
navBarColor = navigationBar.barTintColor;
currentThemeColor = [manager themeColor];
XCTAssertEqualObjects(navBarColor, currentThemeColor);
}
Right now my test fails saying that the value for the navBarColor is null, while my currentThemeColor is populated with the correct UIColorObject. I believe this is because the barTintColor method is only used for setting a color, not retrieving.
I also tried backgroundColor to no avail.
Thanks.
As i have used theme based setting in one of my app here what I have done so far to get navigationBar tint color.
Get Navigation bar tint color:
AppDelegate *objPCAppDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
NSLog(#"%#",[objPCAppDelegate.window rootViewController]);
UINavigationController *navController = (UINavigationController*)[objPCAppDelegate.window rootViewController];
NSLog(#"%#",navController.navigationBar.barTintColor);
Don't create New object of UINavigationController just get form your application.window and use it in your test case.
Note: if you are using default color of navigation bar that it will always return nil as there is no color for default navigation bar.
To get color you have to set custom color to navigation bar than & than you can get it in your test case.

Hiding iOS Status Bar's Text

This question is not about hiding the status bar, but merely hiding the text of the status bar.
I could nt find it anywhere to approach this problem
UBER app does this, when we open the side menu in uber, the status bar text disappear,
No you can't hide text of status bar. you can hide status bar with animation something like,
CGRect appFrame = [[UIScreen mainScreen] applicationFrame];
[UIView animateWithDuration:0.7 animations:^{
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
// self.navigationController.navigationBar.frame = self.navigationController.navigationBar.bounds;
self.view.window.frame = CGRectMake(0, 0, appFrame.size.width, appFrame.size.height);
}];
It is in obj c and just for understand concepts, convert in swift!
You can add new view instead of status bar as custom status bar look
Hope this will help :)
int itemToHide = 0;
[[objc_getClass("SBStatusBarStateAggregator") sharedInstance]
beginCoalescentBlock];
[[objc_getClass("SBStatusBarStateAggregator") sharedInstance]
_setItem:itemToHide enabled:NO];
[[objc_getClass("SBStatusBarStateAggregator") sharedInstance]
endCoalescentBlock];
please check this link. it's may help you.

Little line above status bar issue

In my application there was a small line (about 1px white line) above status bar. What could be the problem?
If you have the same background color throughout the app, this should help you (put it in application:didFinishLaunchingWithOptions:) :
self.window.backgroundColor = [UIColor yourColor];
Swift:
window.backgroundColor = UIColor.yourColor();

Adding subviews on UIWindow covers the keyboard called by textfields

I am trying to imitate an alert view and i show a view with two text fields above a view with a translucent background. The problem is that when i try to tap on the text fields , the keyboard is shown behind my translucent view and i can't tap it no more. Is there a solution?
Here is my code:
if (_grayView==nil) {
_grayView = [[UIView alloc]init];
_grayView.frame = [[UIScreen mainScreen]bounds];
_grayView.backgroundColor = [UIColor blackColor];
_grayView.alpha = 0.7;
[[[[UIApplication sharedApplication] windows] lastObject] addSubview:_grayView];
}
//Show the dimensions view when choosing an image
_dimensionsView.hidden = NO;
[[[[UIApplication sharedApplication] windows] lastObject] addSubview:_dimensionsView];
In the _dimensionsView i have the textfileds.
What you're doing isn't a very good idea to begin with. Also be aware that you can't count on windows.lastObject to always be the window you expect. iOS 7 and 8 are more and more liberal with creating new windows for keyboards and modals. You might not be adding your subview to the window you're expecting.

Change color of navigation bar ios6 and ios7

I'm in the process of upgrading my app to iOS7. However I want to preserve the iOS6 interface as well. It works well except for the navigation bar(s). In iOS7 they look great (just the default color with the translucent property to YES. In iOS6 the navigation bars are showing as the default blue bars and I want them to be black translucent.
What I do is check the version of the iOS and then perform some code. In the debugger I see they right version in the vComp variable but the color is not changing. Don't mind the redColor property, that's just for the test. In both ways I am presented with the default color.
Here is my code:
- (void) fixNavBarColor:(UINavigationBar*)bar {
NSArray *vComp = [[UIDevice currentDevice].systemVersion componentsSeparatedByString:#"."];
if ([[vComp objectAtIndex:0] intValue] >= 7) {
bar.barTintColor = [UIColor redColor];
bar.translucent = NO;
}
else {
bar.tintColor = [UIColor redColor];
bar.opaque = YES;
}
}
There is no error or warning.
Any ideas?
You shouldn't set the tintColor straight to navigationBar as it wouldn't be applied to other parts of your app, you should instead use UINavigationBar's appearance to set tintColor which is available on iOS 5.0 onwards.
[[UINavigationBar appearance] setTintColor:"Your Color"];
Use this code for iOS6
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageWithColor:[UIColor colorWithWhite:0 alpha:.8]]
forBarMetrics:UIBarMetricsDefault];

Resources