mirror of
https://github.com/apache/cordova-plugin-statusbar.git
synced 2026-04-27 00:00:06 +08:00
Added statusbar plugin.
This controls whether the statusbar overlays the webview in iOS 7, as well as allows changing of the statusbar styles.
This commit is contained in:
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
Licensed to the Apache Software Foundation (ASF) under one
|
||||
or more contributor license agreements. See the NOTICE file
|
||||
distributed with this work for additional information
|
||||
regarding copyright ownership. The ASF licenses this file
|
||||
to you under the Apache License, Version 2.0 (the
|
||||
"License"); you may not use this file except in compliance
|
||||
with the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing,
|
||||
software distributed under the License is distributed on an
|
||||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, either express or implied. See the License for the
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
NOTE: plugman/cordova cli should have already installed this,
|
||||
but you need the value UIViewControllerBasedStatusBarAppearance
|
||||
in your Info.plist as well to set the styles in iOS 7
|
||||
*/
|
||||
|
||||
#import "CDVStatusBar.h"
|
||||
|
||||
@implementation CDVStatusBar
|
||||
|
||||
- (id)settingForKey:(NSString*)key
|
||||
{
|
||||
return [self.commandDelegate.settings objectForKey:[key lowercaseString]];
|
||||
}
|
||||
|
||||
- (void)pluginInitialize
|
||||
{
|
||||
_statusBarOverlaysWebView = YES; // default
|
||||
|
||||
NSString* setting = @"StatusBarOverlaysWebView";
|
||||
if ([self settingForKey:setting]) {
|
||||
self.statusBarOverlaysWebView = [(NSNumber*)[self settingForKey:setting] boolValue];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) setStatusBarOverlaysWebView:(BOOL)statusBarOverlaysWebView
|
||||
{
|
||||
// we only care about the latest iOS version or a change in setting
|
||||
if (!IsAtLeastiOSVersion(@"7.0") || statusBarOverlaysWebView == _statusBarOverlaysWebView) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (statusBarOverlaysWebView) {
|
||||
|
||||
CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame;
|
||||
CGRect bounds = self.viewController.view.bounds;
|
||||
bounds.origin.y = 0;
|
||||
bounds.size.height += statusBarFrame.size.height;
|
||||
|
||||
self.webView.frame = bounds;
|
||||
|
||||
} else {
|
||||
CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame;
|
||||
CGRect bounds = self.viewController.view.bounds;
|
||||
bounds.origin.y += statusBarFrame.size.height;
|
||||
bounds.size.height -= statusBarFrame.size.height;
|
||||
|
||||
self.webView.frame = bounds;
|
||||
}
|
||||
|
||||
_statusBarOverlaysWebView = statusBarOverlaysWebView;
|
||||
}
|
||||
|
||||
- (BOOL) statusBarOverlaysWebView
|
||||
{
|
||||
return _statusBarOverlaysWebView;
|
||||
}
|
||||
|
||||
- (void) statusBarOverlaysWebView:(CDVInvokedUrlCommand*)command
|
||||
{
|
||||
id value = [command.arguments objectAtIndex:0];
|
||||
if (!([value isKindOfClass:[NSNumber class]])) {
|
||||
value = [NSNumber numberWithBool:YES];
|
||||
}
|
||||
|
||||
self.statusBarOverlaysWebView = [value boolValue];
|
||||
}
|
||||
|
||||
- (void) styleDefault:(CDVInvokedUrlCommand*)command
|
||||
{
|
||||
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
|
||||
}
|
||||
|
||||
- (void) styleLightContent:(CDVInvokedUrlCommand*)command
|
||||
{
|
||||
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
|
||||
}
|
||||
|
||||
- (void) styleBlackTranslucent:(CDVInvokedUrlCommand*)command
|
||||
{
|
||||
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent];
|
||||
}
|
||||
|
||||
- (void) styleBlackOpaque:(CDVInvokedUrlCommand*)command
|
||||
{
|
||||
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque];
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user