【问题标题】:How to set Font Of tabbar title in objective-C如何在objective-C中设置标签栏标题的字体
【发布时间】:2015-12-02 16:59:34
【问题描述】:

我想将tabBar标题的字体设置为ubuntu,但我无法设置。

我为此编写了以下代码:

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

【问题讨论】:

  • 检查字体是否添加正确,否则尝试添加其他字体并检查一次
  • 是的字体添加正确

标签: ios objective-c fonts set tabbar


【解决方案1】:

Objective 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 Fonts and Color

【讨论】:

    【解决方案2】:

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

    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;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-14
      • 2016-01-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多