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 {
|
@interface CDVStatusBar : CDVPlugin {
|
||||||
@protected
|
@protected
|
||||||
BOOL _statusBarOverlaysWebView;
|
BOOL _statusBarOverlaysWebView;
|
||||||
|
@protected
|
||||||
|
UIView* _statusBarBackgroundView;
|
||||||
}
|
}
|
||||||
|
|
||||||
@property (atomic, assign) BOOL statusBarOverlaysWebView;
|
@property (atomic, assign) BOOL statusBarOverlaysWebView;
|
||||||
@ -34,5 +36,6 @@
|
|||||||
- (void) styleBlackTranslucent:(CDVInvokedUrlCommand*)command;
|
- (void) styleBlackTranslucent:(CDVInvokedUrlCommand*)command;
|
||||||
- (void) styleBlackOpaque:(CDVInvokedUrlCommand*)command;
|
- (void) styleBlackOpaque:(CDVInvokedUrlCommand*)command;
|
||||||
|
|
||||||
|
- (void) statusBarBackgroundColorByName:(CDVInvokedUrlCommand*)command;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -36,6 +36,11 @@
|
|||||||
{
|
{
|
||||||
_statusBarOverlaysWebView = YES; // default
|
_statusBarOverlaysWebView = YES; // default
|
||||||
|
|
||||||
|
CGRect frame = [[UIApplication sharedApplication] statusBarFrame];
|
||||||
|
|
||||||
|
_statusBarBackgroundView = [[UIView alloc] initWithFrame:frame];
|
||||||
|
_statusBarBackgroundView.backgroundColor = [UIColor blackColor];
|
||||||
|
|
||||||
NSString* setting = @"StatusBarOverlaysWebView";
|
NSString* setting = @"StatusBarOverlaysWebView";
|
||||||
if ([self settingForKey:setting]) {
|
if ([self settingForKey:setting]) {
|
||||||
self.statusBarOverlaysWebView = [(NSNumber*)[self settingForKey:setting] boolValue];
|
self.statusBarOverlaysWebView = [(NSNumber*)[self settingForKey:setting] boolValue];
|
||||||
@ -57,6 +62,8 @@
|
|||||||
bounds.size.height += statusBarFrame.size.height;
|
bounds.size.height += statusBarFrame.size.height;
|
||||||
|
|
||||||
self.webView.frame = bounds;
|
self.webView.frame = bounds;
|
||||||
|
|
||||||
|
[_statusBarBackgroundView removeFromSuperview];
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame;
|
CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame;
|
||||||
@ -65,6 +72,8 @@
|
|||||||
bounds.size.height -= statusBarFrame.size.height;
|
bounds.size.height -= statusBarFrame.size.height;
|
||||||
|
|
||||||
self.webView.frame = bounds;
|
self.webView.frame = bounds;
|
||||||
|
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque];
|
||||||
|
[self.webView.superview addSubview:_statusBarBackgroundView];
|
||||||
}
|
}
|
||||||
|
|
||||||
_statusBarOverlaysWebView = statusBarOverlaysWebView;
|
_statusBarOverlaysWebView = statusBarOverlaysWebView;
|
||||||
@ -105,4 +114,17 @@
|
|||||||
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque];
|
[[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
|
@end
|
||||||
|
@ -46,6 +46,10 @@ StatusBar.styleBlackOpaque = function() {
|
|||||||
exec(null, null, "StatusBar", "styleBlackOpaque", []);
|
exec(null, null, "StatusBar", "styleBlackOpaque", []);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
StatusBar.statusBarBackgroundColorByName = function(colorname) {
|
||||||
|
exec(null, null, "StatusBar", "statusBarBackgroundColorByName", [colorname]);
|
||||||
|
}
|
||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
StatusBar.isVisible = true;
|
StatusBar.isVisible = true;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user