2015-09-07 55 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; 
相關問題