Added ability to set statusbar background color by hex string.

This commit is contained in:
Shazron Abdullah 2013-10-06 01:18:06 -07:00
parent da275b579f
commit 058c6b71cc
3 changed files with 25 additions and 0 deletions

View File

@ -37,5 +37,6 @@
- (void) styleBlackOpaque:(CDVInvokedUrlCommand*)command;
- (void) statusBarBackgroundColorByName:(CDVInvokedUrlCommand*)command;
- (void) statusBarBackgroundColorByHexString:(CDVInvokedUrlCommand*)command;
@end

View File

@ -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

View File

@ -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;