更改UITabBarItem中的字体
嗨,我有这个代码,它不工作,我做错了什么?
- (void)viewDidLoad { [self.tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"AmericanTypewriter" size:20.0f], UITextAttributeFont, nil] forState:UIControlStateDisabled]; }
顺便说一句,这不是我viewDidLoad唯一的事情,但我只是想告诉你们,那我把它放在哪里。
按照: 如何更改iOS 5中的UITabBarItem文本的颜色
它看起来像解决scheme可能是发送消息到外观代理,而不是一个项目:
(在iOS 7.0以上不推荐)
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"AmericanTypewriter" size:20.0f], UITextAttributeFont, nil] forState:UIControlStateNormal];
对于iOS 7.0+使用:
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"AmericanTypewriter" size:20.0f], NSFontAttributeName, nil] forState:UIControlStateNormal];
迅速的方式,为懒惰:
UITabBarItem.appearance().setTitleTextAttributes([NSFontAttributeName: UIFont.systemFontOfSize(10)], forState: .normal) UITabBarItem.appearance().setTitleTextAttributes([NSFontAttributeName: UIFont.systemFontOfSize(10)], forState: .selected)
Swift 3
UITabBarItem.appearance().setTitleTextAttributes([NSFontAttributeName: UIFont(name: "OpenSans", size: 10)!], for: .normal)