mirror of
https://github.com/apache/cordova-plugin-statusbar.git
synced 2025-01-19 01:12:49 +08:00
Added statusbar background, including API to change its background color
This commit is contained in:
parent
2e15c9c025
commit
da275b579f
@ -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
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user