Changing font size of tabbaritem

后端 未结 10 1753
忘掉有多难
忘掉有多难 2020-11-30 06:18

Is it possible to change the font size of tabs?

10条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-30 07:03

    [Update] iOS 7.0+ version of @cancer86's nice answer:

    [[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];
    

    The main change is that UITextAttributeTextColor and UITextAttributeFont are both deprecated

    In order to apply it to all tabs (thanks to @ToolmakerSteve for pointing out)

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

提交回复
热议问题