【问题标题】:Navigation Title Chopped with external Font 'FuturaStd-Book'使用外部字体“FuturaStd-Book”截断的导航标题
【发布时间】:2018-06-13 19:15:49
【问题描述】:

使用外部字体“FuturaStd-Book”在导航中截断标题。

尝试使用以下代码减小字体大小,但标题仍被截断。

[[UINavigationBar appearance] setTitleTextAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"FuturaStd-Book" size:16]}];

请帮我解决这个问题...

【问题讨论】:

    标签: ios objective-c uinavigationcontroller navigation uinavigationitem


    【解决方案1】:

    以下代码对齐navigationItem 标题。 (仅适用于 iOS 11 - 但导航返回和标题 y 位置不同)

    NSMutableParagraphStyle *style =  [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
    style.alignment = NSTextAlignmentCenter;
    style.firstLineHeadIndent = 1.0f;
    style.lineSpacing = 2; //Change spacing between lines
    style.paragraphSpacing = 2; //Change space between paragraphs        
    
    [[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor blackColor],
                                                                   NSBackgroundColorAttributeName:[UIColor clearColor],
                                                                   NSFontAttributeName:[UIFont fontWithName:@"FuturaStd-Book" size:18],
                                                                   NSParagraphStyleAttributeName: style }];
    

    【讨论】:

      【解决方案2】:

      您必须使用navigationItemtitleView。在你的 VC 中试试这个:

          UILabel * headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 400.0, 44.0)];
          headerLabel.textAlignment = NSTextAlignmentCenter;
          headerLabel.backgroundColor = [UIColor clearColor];
          headerLabel.text = @"Register";
          headerLabel.font = [UIFont fontWithName:@"FuturaStd-Book" size:16];
          headerLabel.textColor = [UIColor blackColor];
          self.navigationItem.titleView = headerLabel;
      

      输出:

      【讨论】:

      • 感谢您的回答 :) 更新上述代码后还面临 2 个问题 1. 导航返回按钮文本未显示,仅显示箭头。 2.我的项目中还有几个控制器,需要在所有控制器中设置titleview..可以在单行代码更改中更新吗?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-07-28
      • 1970-01-01
      • 2019-10-28
      • 1970-01-01
      • 1970-01-01
      • 2012-03-26
      相关资源
      最近更新 更多