Skip to content

Commit

Permalink
add tab title color
Browse files Browse the repository at this point in the history
  • Loading branch information
cheekiatng committed May 5, 2015
1 parent 35c0034 commit ba6da79
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
17 changes: 17 additions & 0 deletions apidoc/Titanium/UI/Tab.yml
Expand Up @@ -251,6 +251,23 @@ properties:
summary: Key identifying a string from the locale file to use for the tab title. Only one of `title` or `titleid` should be specified.
type: String

- name: titleColor
summary: Defines the color of the title of tab when it's inactive.
description: |
The color of the title of the tab when it's inactive. If not defined, it will use the default tint color.
type: String
since: "4.1.0"
osver: {ios: {min: "5.0"}}
platforms: [iphone,ipad]

- name: activeTitleColor
summary: Defines the color of the title of tab when it's active.
description: |
The color of the title of the tab when it's active. If not defined, it will use the default tint color.
type: String
since: "4.1.0"
osver: {ios: {min: "5.0"}}
platforms: [iphone,ipad]

- name: touchEnabled
platforms: [mobileweb]
Expand Down
7 changes: 6 additions & 1 deletion iphone/Classes/TiUITabGroup.m
Expand Up @@ -383,7 +383,12 @@ -(void) setActiveTabIconTint_:(id)value
{
TiColor* color = [TiUtils colorValue:value];
//A nil tintColor is fine, too.
controller.tabBar.selectedImageTintColor = color.color;
if ([TiUtils isIOS8OrGreater]) {
controller.tabBar.tintColor = color.color;
}
else {
controller.tabBar.selectedImageTintColor = color.color; //deprecated for >= ios8
}
}

#pragma mark Public APIs
Expand Down
23 changes: 23 additions & 0 deletions iphone/Classes/TiUITabProxy.m
Expand Up @@ -51,6 +51,8 @@ -(void)_configure
[self replaceValue:nil forKey:@"badge" notification:NO];
[self replaceValue:NUMBOOL(YES) forKey:@"iconIsMask" notification:NO];
[self replaceValue:NUMBOOL(YES) forKey:@"activeIconIsMask" notification:NO];
[self replaceValue:nil forKey:@"titleColor" notification:NO];
[self replaceValue:nil forKey:@"activeTitleColor" notification:NO];
[super _configure];
}

Expand Down Expand Up @@ -536,6 +538,15 @@ -(void)updateTabBarItem

systemTab = NO;
ourItem = [[[UITabBarItem alloc] initWithTitle:title image:image selectedImage:activeImage] autorelease];

TiColor *titleColor = [TiUtils colorValue:[self valueForKey:@"titleColor"]];
if (titleColor) {
[ourItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[titleColor color], NSForegroundColorAttributeName, nil] forState:UIControlStateNormal];
}
TiColor *activeTitleColor = [TiUtils colorValue:[self valueForKey:@"activeTitleColor"]];
if (activeTitleColor) {
[ourItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[activeTitleColor color], NSForegroundColorAttributeName, nil] forState:UIControlStateSelected];
}
[ourItem setBadgeValue:badgeValue];
[rootController setTabBarItem:ourItem];
}
Expand Down Expand Up @@ -582,6 +593,18 @@ -(void)setIconIsMask:(id)value
}
}

-(void)setTitleColor:(id)value
{
[self replaceValue:value forKey:@"titleColor" notification:NO];
[self updateTabBarItem];
}

-(void)setActiveTitleColor:(id)value
{
[self replaceValue:value forKey:@"activeTitleColor" notification:NO];
[self updateTabBarItem];
}

-(void)setActiveIconIsMask:(id)value
{
[self replaceValue:value forKey:@"activeIconIsMask" notification:NO];
Expand Down

0 comments on commit ba6da79

Please sign in to comment.