代码之家  ›  专栏  ›  技术社区  ›  PrasathBabu

导航标题用外部字体“FuturaStd Book”切碎

  •  0
  • PrasathBabu  · 技术社区  · 8 年前

    Navigation Item Title Chopped

    标题用外部字体“FuturaStd Book”在导航中切掉。

    试图用以下代码减小字体大小,但标题仍被切掉。

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

    请在这方面帮助我。。。

    2 回复  |  直到 8 年前
        1
  •  1
  •   PrasathBabu    8 年前

    以下代码对齐 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
  •  0
  •   Imad Ali Lennet    8 年前

    你必须使用 titleView navigationItem . 在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;
    

    输出:

    enter image description here