2010-04-05 9 views

Antwort

0

Eigentlich gibt es einen Weg.

NSMutableArray *tabBarItems = [[[[[self.view subviews] objectAtIndex:1] subviews] mutableCopy] autorelease]; 

for (int item = 0; item < [tabBarItems count]; item++) { 
    for (int subview = 0; subview < [[[tabBarItems objectAtIndex:item] subviews] count]; subview++) { 
     for (int item = 0; item < [tabBarItems count]; item++) { 
      for (int subview = 0; subview < [[[tabBarItems objectAtIndex:item] subviews] count]; subview++) { 
       if ([[[[tabBarItems objectAtIndex:item] subviews] objectAtIndex:subview] isKindOfClass:NSClassFromString(@"UITabBarButtonLabel")]) 
        [[[[tabBarItems objectAtIndex:item] subviews] objectAtIndex:subview] setFont:[UIFont systemFontOfSize:6.0f]]; 
      } 
     } 
    } 
} 
5
TabBarIncreaseFonts(self.tabBarController); 


void TabBarIncreaseFonts(UITabBarController* customTabBarController) 
{ 

    for(UIView* controlLevelFirst in [customTabBarController.tabBar subviews]) 
    { 

     if(![controlLevelFirst isKindOfClass:NSClassFromString(@"UITabBarButton")]) 
      continue; 

     for(id controlLevelSecond in [controlLevelFirst subviews]) 
     { 
      [controlLevelSecond setBounds: CGRectMake(0, 0, 100, 48)]; 

      if(![controlLevelSecond isKindOfClass:NSClassFromString(@"UITabBarButtonLabel")]) 
       continue; 

      [controlLevelSecond setFont: [UIFont boldSystemFontOfSize:20]]; 
      [controlLevelSecond setFrame: CGRectMake(0, 0, 96, 48)]; 
      [controlLevelSecond setTextAlignment:UITextAlignmentCenter]; 
     } 
    } 
} 
59

Ich empfehle einen besseren Weg:

[yourTabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: 
    [UIColor whiteColor], UITextAttributeTextColor, 
    [NSValue valueWithUIOffset:UIOffsetMake(0,0)], UITextAttributeTextShadowOffset, 
    [UIFont fontWithName:@"Helvetica" size:18.0], UITextAttributeFont, nil] 
    forState:UIControlStateNormal]; 
+9

Es funktioniert nur in iOS5.0 (oder höher) .. – Kjuly

+0

schön, seine Werke absolut gut für mich .. Dank – Gaurav

+0

Welcher Ort tun müssen, um Sie über Stück Code schreiben? Ich versuche es nach [self.tabBarController setViewControllers: aControllerList animiert: YES]; aber das hilft nicht. – Abhinav

20
for(UIViewController *tab in self.tabBarController.viewControllers) 

{   
    [tab.tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: 
    [UIFont fontWithName:@"Helvetica" size:20.0], UITextAttributeFont, nil] 
    forState:UIControlStateNormal]; 
} 
+0

UPDATE: Siehe voghDevs Antwort für iOS 7.0+ Version, die veraltet UITextAttributeFont vermeidet. – ToolmakerSteve

1

[dies hier für meine eigene Referenz zu verlassen, nur ein Riff aus den anderen Arbeits Antworten. Für mem ist es ein Update für iOS 7, die über die Frage durch ein Bit ...]

@implementation UITabBarController (Util) 

- (void) fixForIos7 { 
    if (!IS_IOS7) 
     return; 
    UIFont *tabBarFont = [UIFont systemFontOfSize:12]; 
    NSDictionary *titleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys: 
      tabBarFont, UITextAttributeFont, nil]; 
    for(UIViewController *tab in self.viewControllers) { 
     [tab.tabBarItem setTitleTextAttributes:titleTextAttributes forState:UIControlStateNormal]; 
    } 
} 
@end 

die fehlende Methode ist

#define IS_IOS7 (UIDevice.currentDevice.systemVersion.floatValue > 6.9) 
7

Einfach in iOS 5.0 oder höher:

[[UITabBarItem appearance] setTitleTextAttributes:@{UITextAttributeFont:[UIFont boldSystemFontOfSize:15]} forState:UIControlStateNormal]; 
+0

gute Lösung, aber verwenden Sie 'NSFontAttributeName' anstelle von' UITextAttributeFont' – Laszlo

9

[Update] iOS 7.0+ Version von nette Antwort des @ cancer86:

[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: 
                [UIColor whiteColor], NSForegroundColorAttributeName, 
                [UIFont fontWithName:@"Helvetica" size:tabFontSize], 
                NSFontAttributeName, 
                nil] forState:UIControlStateNormal]; 

[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: 
                [UIColor redColor], NSForegroundColorAttributeName, 
                [UIFont fontWithName:@"Helvetica" size:tabFontSize], NSFontAttributeName, 
                nil] forState:UIControlStateSelected]; 

Die wichtigste Änderung ist, dass UITextAttributeTextColor und UITextAttributeFont beide

veraltet

Um es auf allen Registerkarten

for(UIViewController *tab in self.tabBarController.viewControllers) 
{   
    [tab.tabBarItem setTitleTextAttributes: ...]; 
} 
+0

.. auf alle Registerkarten, aus spatls Antwort 'für (Registerkarte UIViewController * in self.tabBarController.viewControllers) [tab.tabBarItem setTitleTextAttributes: ...' – ToolmakerSteve

+0

ok Antwort aktualisiert – voghDev

+0

können wir schnelle 3-Version dafür haben –

12

IN Swift (Danke für den Hinweis auf @ToolmakerSteve) 2,0

override func viewDidLoad() { 
    super.viewDidLoad() 

    let appearance = UITabBarItem.appearance() 
    let attributes: [String: AnyObject] = [NSFontAttributeName:UIFont(name: "American Typewriter", size: 12)!, NSForegroundColorAttributeName: UIColor.orangeColor()] 
    appearance.setTitleTextAttributes(attributes, forState: .Normal) 

} 

In Swift 3.0

override func viewDidLoad() { 
    super.viewDidLoad() 

    let appearance = UITabBarItem.appearance() 
    let attributes: [String: AnyObject] = [NSFontAttributeName:UIFont(name: "American Typewriter", size: 12)!, NSForegroundColorAttributeName: UIColor.orange] 
    appearance.setTitleTextAttributes(attributes, for: .normal) 
}