Changing font in UITabBarItem

前端 未结 5 1243
旧巷少年郎
旧巷少年郎 2020-12-28 14:27

Hi I have this code and it doesn\'t work, what am I doing wrong?

- (void)viewDidLoad
{    
    [self.tabBarItem setTitleTextAttributes:[NSDictionary dictiona         


        
相关标签:
5条回答
  • 2020-12-28 14:36

    Swift 3

    UITabBarItem.appearance().setTitleTextAttributes([NSFontAttributeName: UIFont(name: "OpenSans", size: 10)!], for: .normal)
    
    0 讨论(0)
  • 2020-12-28 14:40

    As per: How to change the Color of text in UITabBarItem in iOS 5

    It looks like the solution may be sending the message to the appearance proxy, instead of one item:

    (Deprecated in iOS 7.0+)

    [[UITabBarItem appearance] setTitleTextAttributes:@{UITextAttributeFont: [UIFont fontWithName:@"AmericanTypewriter" size:20.0f]} forState:UIControlStateNormal];
    

    For iOS 7.0+ use:

    [[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName: [UIFont fontWithName:@"AmericanTypewriter" size:20.0f]} forState:UIControlStateNormal];
    
    0 讨论(0)
  • 2020-12-28 14:52

    Swift 4.1 and custom font

    UITabBarItem.appearance().setTitleTextAttributes([NSAttributedString.Key.font: UIFont(name: "Montserrat-Medium", size: 11)], for: .normal)
    UITabBarItem.appearance().setTitleTextAttributes([NSAttributedString.Key.font: UIFont(name: "Montserrat-Medium", size: 11)], for: .selected)
    
    0 讨论(0)
  • 2020-12-28 14:57

    Swift 4

    UITabBarItem.appearance().setTitleTextAttributes([NSAttributedString.Key.font: UIFont.tabbar], for: .normal)
    
    0 讨论(0)
  • 2020-12-28 15:01

    Swift way, for lazies:

    UITabBarItem.appearance().setTitleTextAttributes([NSFontAttributeName: UIFont.systemFontOfSize(10)], forState: .normal)
    UITabBarItem.appearance().setTitleTextAttributes([NSFontAttributeName: UIFont.systemFontOfSize(10)], forState: .selected)
    
    0 讨论(0)
提交回复
热议问题