Permalink
Browse files

NIB Localization now also works with UISegmentedControls and UITabBar…

…s, thx to @cldrr
  • Loading branch information...
1 parent b12f0b9 commit 1e3313592cd37b040a247974851cb2ce322ef0e7 @myell0w myell0w committed Mar 24, 2011
Showing with 33 additions and 2 deletions.
  1. +33 −2 InterfaceBuilder/UIView+CWNibLocalizations.m
View
35 InterfaceBuilder/UIView+CWNibLocalizations.m
@@ -34,8 +34,8 @@ -(void)localizeValueForKey:(NSString*)key
{
NSString* oldValue = [self valueForKey:key];
NSString* newValue = [self localizedValue:oldValue];
-
- if (oldValue != newValue) {
+
+ if (oldValue != newValue) {
[self setValue:newValue forKey:key];
}
}
@@ -54,15 +54,46 @@ -(void)localizeButton
}
}
+-(void)localizeSegmentedControl
+{
+ UISegmentedControl* castSC = (UISegmentedControl*) self;
+ for (int index = 0; index < castSC.numberOfSegments; index++)
+ {
+ NSString* title = [castSC titleForSegmentAtIndex:index];
+ [castSC setTitle:[self localizedValue:title] forSegmentAtIndex:index];
+ }
+}
+
+-(void)localizeTabBar
+{
+ UITabBar* tabBar = (UITabBar*) self;
+
+ NSArray* tabBarItems = tabBar.items;
+ for (UITabBarItem* item in tabBarItems)
+ {
+ NSString* title = item.title;
+ [item setTitle:[self localizedValue:title]];
+ }
+
+}
+
-(void)awakeFromNib
{
+ //NSLog("Class: %@", self.name);
if ([self respondsToSelector:@selector(text)]) {
[self localizeValueForKey:@"text"];
} else if ([self respondsToSelector:@selector(title)]) {
[self localizeValueForKey:@"title"];
} else if ([self isKindOfClass:[UIButton class]]) {
[self localizeButton];
}
+ else if ([self isKindOfClass:[UISegmentedControl class]]) {
+ [self localizeSegmentedControl];
+ }
+ else if ([self isKindOfClass:[UITabBar class]])
+ {
+ [self localizeTabBar];
+ }
if ([self respondsToSelector:@selector(placeholder)]) {
[self localizeValueForKey:@"placeholder"];

0 comments on commit 1e33135

Please sign in to comment.