mirror of
https://github.com/apache/cordova-plugin-statusbar.git
synced 2026-05-16 00:03:40 +08:00
Added ability to set statusbar background color by hex string.
This commit is contained in:
@@ -37,5 +37,6 @@
|
||||
- (void) styleBlackOpaque:(CDVInvokedUrlCommand*)command;
|
||||
|
||||
- (void) statusBarBackgroundColorByName:(CDVInvokedUrlCommand*)command;
|
||||
- (void) statusBarBackgroundColorByHexString:(CDVInvokedUrlCommand*)command;
|
||||
|
||||
@end
|
||||
|
||||
@@ -127,4 +127,24 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void) statusBarBackgroundColorByHexString:(CDVInvokedUrlCommand*)command
|
||||
{
|
||||
NSString* value = [command.arguments objectAtIndex:0];
|
||||
if (!([value isKindOfClass:[NSString class]])) {
|
||||
value = @"#000000";
|
||||
}
|
||||
|
||||
if (![value hasPrefix:@"#"] || [value length] < 7) {
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned int rgbValue = 0;
|
||||
NSScanner* scanner = [NSScanner scannerWithString:value];
|
||||
[scanner setScanLocation:1];
|
||||
[scanner scanHexInt:&rgbValue];
|
||||
|
||||
_statusBarBackgroundView.backgroundColor = [UIColor colorWithRed:((rgbValue & 0xFF0000) >> 16)/255.0 green:((rgbValue & 0xFF00) >> 8)/255.0 blue:(rgbValue & 0xFF)/255.0 alpha:1.0];
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
||||
@@ -50,6 +50,10 @@ StatusBar.statusBarBackgroundColorByName = function(colorname) {
|
||||
exec(null, null, "StatusBar", "statusBarBackgroundColorByName", [colorname]);
|
||||
}
|
||||
|
||||
StatusBar.statusBarBackgroundColorByHexString = function(hexString) {
|
||||
exec(null, null, "StatusBar", "statusBarBackgroundColorByHexString", [hexString]);
|
||||
}
|
||||
|
||||
// TODO:
|
||||
StatusBar.isVisible = true;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user