You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by sh...@apache.org on 2014/03/13 20:58:32 UTC
[03/35] git commit: Added statusbar background,
including API to change its background color
Added statusbar background, including API to change its background color
Project: http://git-wip-us.apache.org/repos/asf/cordova-statusbar/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-statusbar/commit/da275b57
Tree: http://git-wip-us.apache.org/repos/asf/cordova-statusbar/tree/da275b57
Diff: http://git-wip-us.apache.org/repos/asf/cordova-statusbar/diff/da275b57
Branch: refs/heads/master
Commit: da275b579fbb3642635d0777082f7b96ae003e20
Parents: 2e15c9c
Author: Shazron Abdullah <sh...@apache.org>
Authored: Sun Oct 6 00:47:33 2013 -0700
Committer: Shazron Abdullah <sh...@apache.org>
Committed: Sun Oct 6 00:47:33 2013 -0700
----------------------------------------------------------------------
src/ios/CDVStatusBar.h | 3 +++
src/ios/CDVStatusBar.m | 22 ++++++++++++++++++++++
www/statusbar.js | 4 ++++
3 files changed, 29 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-statusbar/blob/da275b57/src/ios/CDVStatusBar.h
----------------------------------------------------------------------
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
http://git-wip-us.apache.org/repos/asf/cordova-statusbar/blob/da275b57/src/ios/CDVStatusBar.m
----------------------------------------------------------------------
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
http://git-wip-us.apache.org/repos/asf/cordova-statusbar/blob/da275b57/www/statusbar.js
----------------------------------------------------------------------
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;