2015-09-07 63 views
5

我想将tabBar标题的字体设置为ubuntu,但是我无法设置它。如何设置目标中的tabbar标题的字体-c

我写下面的代码为:

self.tabBarController.navigationController.navigationBar.titleTextAttributes = 
     @{NSForegroundColorAttributeName: [UIColor whiteColor], 
     NSFontAttributeName:[UIFont fontWithName:@"Ubuntu" size:9.0f]}; 
+0

检查字体正确与否添加其他尝试这种添加其他字体和检查一次 –

+0

是的字体添加正确 – Harshit

回答

2

目标C代码 -

[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"your_font_name" size:20.0f], NSFontAttributeName, nil] forState:UIControlStateNormal]; 

夫特代码 -

UITabBarItem.appearance().setTitleTextAttributes(
     [NSFontAttributeName: UIFont(name:"your_font_name", size:11)!, 
      NSForegroundColorAttributeName: UIColor(rgb: 0x929292)], 
     forState: .Normal) 

更多refrence- iOS5 TabBar Fonts and Color

+0

不起作用 – Harshit

1

我找到了一个解决方案.. 首先创建自定义标签之后,我改变该字体....

UIView *iv = [[UIView alloc] initWithFrame:CGRectMake(0,0,230.0,80.0)]; 
UILabel *lbl = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 230, 80)]; 
lbl.textColor = [UIColor whiteColor]; 
lbl.font = [UIFont fontWithName:@"Ubuntu" size:18.0f]; 
lbl.textAlignment = NSTextAlignmentCenter; 
lbl.text = [NSString stringWithFormat:@"%lu Store Found",(unsigned long)arrOfferList.count]; 
[iv addSubview:lbl]; 
self.tabBarController.navigationItem.titleView = iv;