我正在做一个基于tabbarController的应用程序。我有3个tabbar项目。
我的问题是:如何更改标签栏项目标题的字体样式?
答案 0 :(得分:11)
[self.tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:@"AmericanTypewriter" size:20.0f], UITextAttributeFont,
[UIColor blackColor], UITextAttributeTextColor,
[UIColor grayColor], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0.0f, 1.0f)], UITextAttributeTextShadowOffset,
nil]];
答案 1 :(得分:1)
这将在整个应用程序中一劳永逸地更改您的UITabBarItem字体
对于Swift在AppDelegate的didFinishLaunching中使用它:
斯威夫特3:
UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.blue,NSFontAttributeName: UIFont(name: "Montserrat", size: 11)!], for: .normal)
UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.red,NSFontAttributeName: UIFont(name: "Montserrat", size: 11)!], for: .selected)
答案 2 :(得分:0)
对不起,我不认为有办法做到这一点。如果你很绝望,你需要编写自己的标签栏。
答案 3 :(得分:0)
可悲的是,除非你建立自己的自定义标签栏,否则目前在iOS上是不可能的,这对iOS5上的故事板来说并不是很困难。
答案 4 :(得分:0)
不可能,创建自定义标签栏子类化UITabbar
答案 5 :(得分:0)
如果您看到此错误:'UITextAttributeTextShadowOffset' is deprecated: first deprecated in iOS 7.0 - Use NSShadowAttributeName with an NSShadow instance as the value.
,请尝试此操作。
NSShadow *shadow = [[NSShadow alloc] init];
shadow.shadowColor = [UIColor grayColor];
shadow.shadowOffset = CGSizeMake(0.0, 0.5);
NSDictionary *attribute = [NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:@"AmericanTypewriter" size:10.0f], NSFontAttributeName,
[UIColor blackColor], NSForegroundColorAttributeName,
shadow,NSShadowAttributeName,nil];
[[UITabBarItem appearance] setTitleTextAttributes:attribute forState:UIControlStateNormal];
答案 6 :(得分:-1)
试试这个。
[[UITabBarItem appearanceWhenContainedIn:[UITabBar class], nil]
setTitleTextAttributes:@{NSForegroundColorAttributeName:
[UIColor colorWithRed:0/255.0f green:130/255.0f blue:202/255.0f alpha:1.0],
NSFontAttributeName:[UIFont fontWithName:@"Signika-Semibold" size:20.0]
}
forState:UIControlStateNormal];