ios - backBarButtonItem有长文本时显示 "..."

标签 ios uinavigationbar uinavigationitem

我是 iOS 编程的新手。我使用应用程序 导航栏 , 并为 设置文本返回 像这样的按钮:

self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"my text" style:UIBarButtonItemStyleBordered target:nil action:nil];

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

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

P/s : 我有引用 "back" text displayed in iOS7 UINavigationBar when view title is long但这对我解决这个问题没有帮助。

最佳答案

试试这个

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];

愿这对你有帮助

关于ios - backBarButtonItem有长文本时显示 "...",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35447365/

相关文章:

ios - 尝试添加 UINavigationBar 按钮时发生崩溃

ios - 全局访问 UIalertview 中的文本字段数据

ios - cordova platform add ios not working on mac(创建ios子项目时出错)

ios - 我们应该如何显示以下 ViewController?

ios - 多个 ScrollView 彼此内部

swift - SlackTextViewController 会干扰导航栏吗?

ios - UINavigationBar 颜色在推送 View Controller 后发生变化

ios - 使用 UIAppearance 移动 UINavigationBar

uikit - 如何在 iOS 13 的导航 Controller 中最初隐藏搜索栏?

ipad - 嵌入在 UINavigationBar/Item 中的 UISegmentedControl