From da275b579fbb3642635d0777082f7b96ae003e20 Mon Sep 17 00:00:00 2001 From: Shazron Abdullah Date: Sun, 6 Oct 2013 00:47:33 -0700 Subject: [PATCH] Added statusbar background, including API to change its background color --- src/ios/CDVStatusBar.h | 3 +++ src/ios/CDVStatusBar.m | 22 ++++++++++++++++++++++ www/statusbar.js | 4 ++++ 3 files changed, 29 insertions(+) diff --git a/src/ios/CDVStatusBar.h b/src/ios/CDVStatusBar.h index 298b3f5..124128e 100644 --- a/src/ios/CDVStatusBar.h +++ b/src/ios/CDVStatusBar.h @@ -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 diff --git a/src/ios/CDVStatusBar.m b/src/ios/CDVStatusBar.m index 9fe4632..e2a660c 100644 --- a/src/ios/CDVStatusBar.m +++ b/src/ios/CDVStatusBar.m @@ -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]; @@ -57,6 +62,8 @@ bounds.size.height += statusBarFrame.size.height; self.webView.frame = bounds; + + [_statusBarBackgroundView removeFromSuperview]; } else { CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame; @@ -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 diff --git a/www/statusbar.js b/www/statusbar.js index 8c461bd..6a2ca9e 100644 --- a/www/statusbar.js +++ b/www/statusbar.js @@ -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;