[英]Custom Trimming Back button text of UINavigationController
环境 :
我正在开发针对我的iOS应用的应用内语言环境更改支持。 这很难听起来,因为UIKit
提供的控件的区域设置与iOS区域设置相关。
我几乎可以解决所有问题,但目前还剩下一件事:
问题 :
当我们使用UINavigationController
推送视图控制器时。 它将自动生成带有先前视图控制器的导航项目标题的后退按钮项目。
但是,如果标题太长而无法显示为后退按钮, UINavigationController
Back
用作后备标题。 自动缩短标题(返回)与系统区域设置相关。 这是我的问题。
我可以合法更改此行为吗?
我制作了自定义UINavigationController
并覆盖了pushViewController:animated:
-(void)pushViewController:(UIViewController *)viewController
animated:(BOOL)animated
{
UINavigationItem* current = self.topViewController.navigationItem;
if(current.backBarButtonItem == nil){
current.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:current.title style:UIBarButtonItemStylePlain target:nil action:nil];
}
UIBarButtonItem* backItem = current.backBarButtonItem;
CGFloat width = [backItem.title sizeWithAttributes:@{}].width;
// Trimming to localized back text
if(width > 70){
backItem.title = [[KKCoreLocale shared] localizedStringForKey:@"Back"];
}
[super pushViewController:viewController animated:animated];
}
我不确定这是最好的解决方案,但是这是合法的并且很有魅力。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.