簡體   English   中英

如何在objective-C中設置tabbar標簽的Font

[英]How to set Font Of tabbar title in objective-C

我想將tabBar標題的字體設置為ubuntu,但我無法設置。

我在下面寫下代碼:

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

目標C代碼 -

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

SWIFT代碼-

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

更多參考 - iOS5 TabBar字體和顏色

我找到了一個解決方案..首先我創建自定義標簽,然后我改變了那個字體....

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;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM