mirror of
https://github.com/apache/cordova-plugin-statusbar.git
synced 2026-04-27 00:00:06 +08:00
Added statusbar background, including API to change its background color
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user