Added statusbar background, including API to change its background color

This commit is contained in:
Shazron Abdullah 2013-10-06 00:47:33 -07:00
parent 2e15c9c025
commit da275b579f
3 changed files with 29 additions and 0 deletions

View File

@ -23,6 +23,8 @@
@interface CDVStatusBar : CDVPlugin {
@protected
BOOL _statusBarOverlaysWebView;
@protected
UIView* _statusBarBackgroundView;
}
@property (atomic, assign) BOOL statusBarOverlaysWebView;
@ -34,5 +36,6 @@
- (void) styleBlackTranslucent:(CDVInvokedUrlCommand*)command;
- (void) styleBlackOpaque:(CDVInvokedUrlCommand*)command;
- (void) statusBarBackgroundColorByName:(CDVInvokedUrlCommand*)command;
@end

View File

@ -36,6 +36,11 @@
{
_statusBarOverlaysWebView = YES; // default
CGRect frame = [[UIApplication sharedApplication] statusBarFrame];
_statusBarBackgroundView = [[UIView alloc] initWithFrame:frame];
_statusBarBackgroundView.backgroundColor = [UIColor blackColor];
NSString* setting = @"StatusBarOverlaysWebView";
if ([self settingForKey:setting]) {
self.statusBarOverlaysWebView = [(NSNumber*)[self settingForKey:setting] boolValue];
@ -58,6 +63,8 @@
self.webView.frame = bounds;
[_statusBarBackgroundView removeFromSuperview];
} else {
CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame;
CGRect bounds = self.viewController.view.bounds;
@ -65,6 +72,8 @@
bounds.size.height -= statusBarFrame.size.height;
self.webView.frame = bounds;
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque];
[self.webView.superview addSubview:_statusBarBackgroundView];
}
_statusBarOverlaysWebView = statusBarOverlaysWebView;
@ -105,4 +114,17 @@
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque];
}
- (void) statusBarBackgroundColorByName:(CDVInvokedUrlCommand*)command
{
id value = [command.arguments objectAtIndex:0];
if (!([value isKindOfClass:[NSString class]])) {
value = @"black";
}
SEL selector = NSSelectorFromString([value stringByAppendingString:@"Color"]);
if ([UIColor respondsToSelector:selector]) {
_statusBarBackgroundView.backgroundColor = [UIColor performSelector:selector];
}
}
@end

View File

@ -46,6 +46,10 @@ StatusBar.styleBlackOpaque = function() {
exec(null, null, "StatusBar", "styleBlackOpaque", []);
};
StatusBar.statusBarBackgroundColorByName = function(colorname) {
exec(null, null, "StatusBar", "statusBarBackgroundColorByName", [colorname]);
}
// TODO:
StatusBar.isVisible = true;