2012-06-27 46 views

回答

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

为什么这是upvoted 7次,当没有这样的方法UITabBarItem? –

+3

对于任何仍然有问题的人:上面键入的方法不正确。您需要在'setTitleTextAttributes:'之后添加'forState:'参数。然后它将编译时不会发出警告并按预期工作。 – element119

0

对不起,我不认为有办法做到这一点。如果你绝望,你需要编写自己的标签栏。

+1

为什么这是upvoted?有针对此早期问题提出的解决方案:http://stackoverflow.com/q/2576592/199364。或者你是否说这里的问题不同? – ToolmakerSteve

+0

@ToolmakerSteve绝对正确。检查我的答案。 –

0

不幸的是,目前在iOS上这是不可能的,除非你建立你自己的自定义标签栏,这对iOS5的故事板不是很难。

0

如果您看到这个错误custome标签栏:'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]; 
-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]; 
+0

请仔细理解它的确切含义? – MeanGreen

1

这将改变乌尔UITabBarItem字体一劳永逸整个应用程序

对于斯威夫特使用这种在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) 
相关问题