Est-il possible de changer la taille de la police des tabs?
Je recommand une meilleure façon:
[yourTabBarItem setTitleTextAtsortingbutes:[NSDictionary dictionaryWithObjectsAndKeys: [UIColor whiteColor], UITextAtsortingbuteTextColor, [NSValue valueWithUIOffset:UIOffsetMake(0,0)], UITextAtsortingbuteTextShadowOffset, [UIFont fontWithName:@"Helvetica" size:18.0], UITextAtsortingbuteFont, nil] forState:UIControlStateNormal];
for(UIViewController *tab in self.tabBarController.viewControllers) { [tab.tabBarItem setTitleTextAtsortingbutes:[NSDictionary dictionaryWithObjectsAndKeys: [UIFont fontWithName:@"Helvetica" size:20.0], UITextAtsortingbuteFont, nil] forState:UIControlStateNormal]; }
DANS Swift 2.0
override func viewDidLoad() { super.viewDidLoad() let appearance = UITabBarItem.appearance() let atsortingbutes: [Ssortingng: AnyObject] = [NSFontAtsortingbuteName:UIFont(name: "American Typewriter", size: 12)!, NSForegroundColorAtsortingbuteName: UIColor.orangeColor()] appearance.setTitleTextAtsortingbutes(atsortingbutes, forState: .Normal) }
Dans Swift 3.0
override func viewDidLoad() { super.viewDidLoad() let appearance = UITabBarItem.appearance() let atsortingbutes: [Ssortingng: AnyObject] = [NSFontAtsortingbuteName:UIFont(name: "American Typewriter", size: 12)!, NSForegroundColorAtsortingbuteName: UIColor.orange] appearance.setTitleTextAtsortingbutes(atsortingbutes, for: .normal) }
[Mise à jour] iOS 7.0+ version de la réponse sympa de @ cancer86:
[[UITabBarItem appearance] setTitleTextAtsortingbutes:[NSDictionary dictionaryWithObjectsAndKeys: [UIColor whiteColor], NSForegroundColorAtsortingbuteName, [UIFont fontWithName:@"Helvetica" size:tabFontSize], NSFontAtsortingbuteName, nil] forState:UIControlStateNormal]; [[UITabBarItem appearance] setTitleTextAtsortingbutes:[NSDictionary dictionaryWithObjectsAndKeys: [UIColor redColor], NSForegroundColorAtsortingbuteName, [UIFont fontWithName:@"Helvetica" size:tabFontSize], NSFontAtsortingbuteName, nil] forState:UIControlStateSelected];
Le principal changement est que UITextAtsortingbuteTextColor et UITextAtsortingbuteFont sont tous les deux obsolètes
Pour l'appliquer à tous les tabs (merci à @ToolmakerSteve pour le signaler)
for(UIViewController *tab in self.tabBarController.viewControllers) { [tab.tabBarItem setTitleTextAtsortingbutes: ...]; }
Simple sous iOS 5.0 ou ultérieur:
[[UITabBarItem appearance] setTitleTextAtsortingbutes:@{UITextAtsortingbuteFont:[UIFont boldSystemFontOfSize:15]} forState:UIControlStateNormal];
TabBarIncreaseFonts(self.tabBarController); void TabBarIncreaseFonts(UITabBarController* customTabBarController) { for(UIView* controlLevelFirst in [customTabBarController.tabBar subviews]) { if(![controlLevelFirst isKindOfClass:NSClassFromSsortingng(@"UITabBarButton")]) continue; for(id controlLevelSecond in [controlLevelFirst subviews]) { [controlLevelSecond setBounds: CGRectMake(0, 0, 100, 48)]; if(![controlLevelSecond isKindOfClass:NSClassFromSsortingng(@"UITabBarButtonLabel")]) continue; [controlLevelSecond setFont: [UIFont boldSystemFontOfSize:20]]; [controlLevelSecond setFrame: CGRectMake(0, 0, 96, 48)]; [controlLevelSecond setTextAlignment:UITextAlignmentCenter]; } } }
[laissant ceci ici pour ma propre reference, juste un riff des autres réponses fonctionnantes. Pour mem c'est un correctif pour iOS 7, ce qui est un peu hors de question …]
@implementation UITabBarController (Util) - (void) fixForIos7 { if (!IS_IOS7) return; UIFont *tabBarFont = [UIFont systemFontOfSize:12]; NSDictionary *titleTextAtsortingbutes = [NSDictionary dictionaryWithObjectsAndKeys: tabBarFont, UITextAtsortingbuteFont, nil]; for(UIViewController *tab in self.viewControllers) { [tab.tabBarItem setTitleTextAtsortingbutes:titleTextAtsortingbutes forState:UIControlStateNormal]; } } @end
la méthode manquante est
#define IS_IOS7 ( UIDevice.currentDevice.systemVersion.floatValue > 6.9 )
En fait, il y a un moyen.
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:NSClassFromSsortingng(@"UITabBarButtonLabel")]) [[[[tabBarItems objectAtIndex:item] subviews] objectAtIndex:subview] setFont:[UIFont systemFontOfSize:6.0f]]; } } } }