xcode 如何更改标签栏控制器项目名称的字体大小?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11221333/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 00:41:56  来源:igfitidea点击:

How to change the font size of the tab bar controller item name?

iphoneobjective-cxcode

提问by Manohar Perepa

I am doing an app based on tabbarController. I have a 3 tabbar items.

我正在做一个基于 tabbarController 的应用程序。我有 3 个标签栏项目。

My question is: How can I change the font-style for the title on the tab-bar item?

我的问题是:如何更改标签栏项目标题的字体样式?

采纳答案by user1478583

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

回答by Ankit Kumar Gupta

This will change ur UITabBarItem fonts once and for all throughout the app

这将在整个应用程序中一劳永逸地更改您的 UITabBarItem 字体

For Swift use this in AppDelegate's didFinishLaunching:

对于 Swift,在 AppDelegate 的 didFinishLaunching 中使用它:

Swift 3:

斯威夫特 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)

回答by gabbler

If you see this error: 'UITextAttributeTextShadowOffset' is deprecated: first deprecated in iOS 7.0 - Use NSShadowAttributeName with an NSShadow instance as the value.,try this.

如果您看到此错误:'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];

回答by Srikar Appalaraju

Sorry, I dont think there's a way to do this. If you're desperate, you'll need to write your own tab bar.

抱歉,我认为没有办法做到这一点。如果您感到绝望,则需要编写自己的标签栏。

回答by Zachary Christopoulos

Sadly, this isn't possible currently on iOS unless you build your own custom tab bar, which isn't very difficult with storyboarding on iOS5.

遗憾的是,这在 iOS 上目前是不可能的,除非您构建自己的自定义标签栏,这对于 iOS5 上的故事板来说并不是很困难。

回答by user1048972

Not possible ,create custome tab bar subclassing UITabbar

不可能,创建自定义标签栏子类化 UITabbar

回答by Bis Cuit

Try this.

尝试这个。

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