当backBarButtonItem有长文本时显示“...”

时间:2016-02-17 03:31:46

标签: ios uinavigationbar uinavigationitem

我是iOS编程的新手。我使用导航栏处理应用,并为返回按钮设置文字,如下所示:

$work_array = array('name'=>urlencode($row['Work']));

它工作正常。但是,当我的文字很长时会出现问题, backBarButtonItem 显示默认文字返回

所以,问题是:如何在 backBarButtonItem 中显示长文本,可能会显示“...”而不是全文。或者我可以使用自定义视图替换默认导航栏吗?

P / s:我已经提到"back" text displayed in iOS7 UINavigationBar when view title is long但是对我来说解决这个问题没什么帮助。

2 个答案:

答案 0 :(得分:2)

试试这个

self.navigationItem.hidesBackButton = YES;
UIButton *btnLeft=[UIButton buttonWithType:UIButtonTypeCustom];
btnLeft.frame=CGRectMake(0, 0, button.widh, button.height);
[btnLeft addTarget:self action:@selector(onClickBackBarItem:) forControlEvents:UIControlEventTouchUpInside];
[btnLeft setTitle:@"YOUR TEXT"  forState:UIControlStateNormal];
btnLeft.titleLabel.font  = [UIFont fontWithName:@"font_name" size:25.0];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btnLeft];

这可以帮助你

答案 1 :(得分:1)

使用sizeToFitUIButton

中显示全文
    UIButton *btnBack = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30, 20) ];
    [btnBack setTitle:@"Skip" forState:UIControlStateNormal];
    btnBack.titleLabel.font = [UIFont fontWithName:@"SFUIText-Medium" size:15];
    [btnBack sizeToFit];
    [btnBack addTarget:self action:@selector(backActionEvent:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btnSkip];