Skip to content

Commit 0621d25

Browse files
committed
Add support for tab bar tint (only on iOS 5 or newer)
1 parent 2749a2a commit 0621d25

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

iOS/TabBar/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ This example shows how to use the tab bar:
5858
plugins.tabBar.init()
5959

6060
plugins.tabBar.create()
61+
// or with an orange tint:
62+
plugins.tabBar.create({selectedImageTintColorRgba: '255,40,0,255'})
63+
6164
plugins.tabBar.createItem("contacts", "Unused, iOS replaces this text by Contacts", "tabButton:Contacts")
6265
plugins.tabBar.createItem("recents", "Unused, iOS replaces this text by Recents", "tabButton:Recents")
6366

iOS/TabBar/TabBar.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,13 @@ function TabBar() {
1515

1616
/**
1717
* Create a native tab bar that can have tab buttons added to it which can respond to events.
18+
*
19+
* @param options Additional options:
20+
* - selectedImageTintColorRgba: Tint color for selected items (defaults to standard light blue), must define the
21+
* color as string e.g. '255,0,0,128' for 50% transparent red. This is only supported on iOS 5 or newer.
1822
*/
19-
TabBar.prototype.create = function() {
20-
cordova.exec("TabBar.create");
23+
TabBar.prototype.create = function(options) {
24+
cordova.exec("TabBar.create", options);
2125
};
2226

2327
/**

iOS/TabBar/TabBar.m

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,22 @@ - (void)create:(NSArray*)arguments withDict:(NSDictionary*)options
132132
tabBar.autoresizesSubviews = YES;
133133
tabBar.hidden = YES;
134134
tabBar.userInteractionEnabled = YES;
135-
tabBar.opaque = YES;
135+
tabBar.opaque = YES;
136136

137-
self.webView.superview.autoresizesSubviews = YES;
137+
NSString *iconTint = [options valueForKey:@"selectedImageTintColorRgba"];
138138

139-
[ self.webView.superview addSubview:tabBar];
139+
if(iconTint && [tabBar respondsToSelector:@selector(setSelectedImageTintColor:)])
140+
{
141+
NSArray *rgba = [iconTint componentsSeparatedByString:@","];
142+
tabBar.selectedImageTintColor = [UIColor colorWithRed:[[rgba objectAtIndex:0] intValue]/255.0f
143+
green:[[rgba objectAtIndex:1] intValue]/255.0f
144+
blue:[[rgba objectAtIndex:2] intValue]/255.0f
145+
alpha:[[rgba objectAtIndex:3] intValue]/255.0f];
146+
}
147+
148+
self.webView.superview.autoresizesSubviews = YES;
149+
150+
[self.webView.superview addSubview:tabBar];
140151
}
141152

142153
-(void) init:(NSMutableArray *)arguments withDict:(NSMutableDictionary *)options

0 commit comments

Comments
 (0)