当我的应用程序运行在RTL设备配置上时,我添加了UIBarButtonItem
到self.navigationItem.leftBarButtonItem
,当LTR设备配置时我添加了self.navigationItem.rightBarButtonItem
。 在这两个配置中添加了UIBarButtonItem
涵盖后面的按钮,这是defualt按钮。添加UIBarButtonItem覆盖UINavigationController后退按钮
这里是我的代码:
let label = UILabel(frame: CGRect(x: 0, y: 0, width: CGFloat(150), height: CGFloat(20)))
label.backgroundColor = UIColor.clear
label.font = UIFont.systemFont(ofSize: 18.0)
label.shadowColor = UIColor(white: 0.0, alpha:0.5)
label.textAlignment = NSTextAlignment.center
label.textColor = UIColor(hexaValue: ConsColors.albums)
label.text = "Just text"
label.sizeToFit()
if UIApplication.shared.userInterfaceLayoutDirection == UIUserInterfaceLayoutDirection.rightToLeft{
self.navigationItem.leftBarButtonItem = UIBarButtonItem(customView: label)
}else{
self.navigationItem.rightBarButtonItem = UIBarButtonItem(customView: label)
}
我甚至有一个正常的系统UIBarButtonItem
尝试。 还试图设置UINavigationcontroller
语义内容属性强制RightToLeft或LefttoRight不起作用。
UINavigationBar.appearance().semanticContentAttribute = .forceRightToleft
我用斯威夫特3时,Xcode 8.1和一个iPad 2的空气与它的操作系统优化版本是9.3.2 有谁知道如何解决它?
将感谢帮助,谢谢。
谢谢,我试过了,它现在不覆盖后退按钮,但我想实现的是返回按钮的一侧和另一侧的按钮/视图,而不是两个按钮在同一侧。这发生在我身上。 –
当我的设备配置LTR时,它的工作原理是,后退按钮位于左侧,第二个按钮位于右侧。虽然设备配置了RTL后退按钮和第二个按钮在右侧彼此相邻。奇怪的行为。并且正如我搜索的那样,没有self.navigationItem.rightItemsSupplementBackButton :( –
谢谢你,你是对的没有必要的if语句。它现在工作。 –