UINavigationBar标题标签文本 [英] UINavigationBar title label text

查看:251
本文介绍了UINavigationBar标题标签文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以缩小标题文字以适应iOS中的 UINavigationBar

Is it possible to get the title text to shrink to fit in the UINavigationBar in iOS.

(对于没有自动布局的人像iPhone应用程序。。

(for portrait iPhone app with no autolayout).

我正在动态设置标题栏但有时文本太长而且此刻它只是将其切断省略号。

I'm setting the title bar dynamically but sometimes the text is too long and at the moment it just cuts it off with an ellipsis.

ie 这就是......

i.e. "This is the t..."

我希望它缩小文字。

推荐答案

您可以创建自己的标题视图来制作它。

You can create your own title view to make it.

这样的事情:

- (void)viewDidLoad
{
    [super viewDidLoad];

  //Do any additional setup after loading the view, typically from a nib.
     UILabel *titleLabelView = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 40)]; //<<---- Actually will be auto-resized according to frame of navigation bar;
    [titleLabelView setBackgroundColor:[UIColor clearColor]];
    [titleLabelView setTextAlignment: NSTextAlignmentCenter];
    [titleLabelView setTextColor:[UIColor whiteColor]];
    [titleLabelView setFont:[UIFont systemFontOfSize: 27]]; //<<--- Greatest font size
    [titleLabelView setAdjustsFontSizeToFitWidth:YES]; //<<---- Allow shrink
     // [titleLabelView setAdjustsLetterSpacingToFitWidth:YES];  //<<-- Another option for iOS 6+
    titleLabelView.text = @"This is a Title";

    navigationBar.topItem.titleView = titleLabelView;

    //....
}

希望这个帮助。

这篇关于UINavigationBar标题标签文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆