我想让我的标签栏项目的字体大小更大。我曾尝试在AppDelegate中这样做:何处/何时/如何设置tabBarItem字体属性属性?
MenuTableViewController *mvc = [[MenuTableViewController alloc] init];
mvc.delegate = self;
mvc.restorationIdentifier = NSStringFromClass([mvc class]);
mvc.restorationClass = [self class];
UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:mvc];
SuperTabBarController *nav = [[SuperTabBarController alloc] init];
JudgeViewController *jvc = [[JudgeViewController alloc] init];
BuzzViewController *bvc = [[BuzzViewController alloc] init];
nav.viewControllers = @[jvc, bvc, nav1];
UIFont *tabBarFont = [UIFont systemFontOfSize:40];
NSDictionary *titleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
tabBarFont, NSFontAttributeName, nil];
for(UIViewController *tab in nav.viewControllers) {
[tab.tabBarItem setTitleTextAttributes:titleTextAttributes forState:UIControlStateNormal];
NSLog(@"yo normal");
}
for(UIViewController *tab in nav.viewControllers) {
[tab.tabBarItem setTitleTextAttributes:titleTextAttributes forState:UIControlStateSelected];
NSLog(@"yo");
}
[UIView transitionWithView:self.window duration:0.5 options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{self.window.rootViewController = nav;} completion:nil];
我也试图定义字典,像这样:
NSDictionary *titleTextAttributes2 = @{NSFontAttributeName:
[UIFont fontWithName:@"Helvetica" size:20]};
这是在通过委托协议,一旦用户登录时调用自定义函数我NSLogs打印出来,但我也得到这个控制台:
button text attributes only respected for UIControlStateNormal, UIControlStateSelected and UIControlStateDisabled. state = 1 is interpreted as UIControlStateSelected.
程序根据需要比标题字体不都用这个命令,尽管日志outpu改变其他运行TS。
于是我把我的自定义视图控制器这里面viewDidLoad中:
UIFont *tabBarFont = [UIFont systemFontOfSize:40];
NSDictionary *titleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
tabBarFont, NSFontAttributeName, nil];
[self.tabBarItem setTitleTextAttributes:titleTextAttributes forState:UIControlStateNormal];
[self.tabBarItem setTitleTextAttributes:titleTextAttributes forState:UIControlStateSelected];
但这也丝毫不影响标签栏标题的字体大小。
我应该在哪里执行这些命令?
谢谢。
编 被标记的答案做什么,我需要,但我注意到,该方法仅工作,如果我使用类范围的制定者,而不是一个实例的制定者。因此,要全局更改标签栏项目的标题文字,这就像一个魅力:
NSDictionary *attribute = @{NSFontAttributeName:
[UIFont fontWithName:@"Helvetica" size:40]};
[[UITabBarItem appearance] setTitleTextAttributes:attribute forState:UIControlStateNormal];
但努力仍然设置一个类实例的属性不工作(这些被称为都在同一个功能,但只有一个生效)。 NSDictionary * attribute2 = @ {NSFontAttributeName: [UIFont fontWithName:@“Helvetica”size:10]}; [nav1.tabBarItem setTitleTextAttributes:attribute2 forState:UIControlStateNormal];
任何人都知道这是为什么?我多次浏览了Apple Dev文档,却没有看到为什么类实例调用没有做任何事情。
谢谢!非常感激。 – 2014-11-24 01:29:19