当我按下a时UIViewController,它在new的后退按钮中有一些标题UIViewController,如果标题中包含很多文本,则在iPhone 4s中看起来不太好,所以我想删除它。
UIViewController
如果我在prepareForSegue函数中添加一些代码,那将是一个麻烦。
prepareForSegue
还有更好的方法吗?
如果要返回箭头,则将以下代码放入AppDelegate文件中didFinishLaunchingWithOptions。
AppDelegate
didFinishLaunchingWithOptions
For Objective-C
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60) forBarMetrics:UIBarMetricsDefault];
For Swift
let BarButtonItemAppearance = UIBarButtonItem.appearance() BarButtonItemAppearance.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.clear], for: .normal)
另一个选择在下面给出。
在 Objective C
Objective C
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
在 Swift
Swift
self.navigationItem.backBarButtonItem = UIBarButtonItem(title:"", style:.plain, target:nil, action:nil)
更新:
let BarButtonItemAppearance = UIBarButtonItem.appearance() let attributes: [NSAttributedStringKey: Any] = [ BarButtonItemAppearance.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.clear], for: .normal) NSAttributedStringKey.font: UIFont.systemFont(ofSize: 0.1), NSAttributedStringKey.foregroundColor: UIColor.clear] BarButtonItemAppearance.setTitleTextAttributes(attributes, for: .normal) BarButtonItemAppearance.setTitleTextAttributes(attributes, for: .highlighted)
更新SWIFT 4.1:
let attributes = [NSAttributedStringKey.font: UIFont(name: "Helvetica-Bold", size: 0.1)!, NSAttributedStringKey.foregroundColor: UIColor.clear] BarButtonItemAppearance.setTitleTextAttributes(attributes, for: .normal) BarButtonItemAppearance.setTitleTextAttributes(attributes, for: .highlighted)
使用偏移
UIBarButtonItem.appearance().setBackButtonTitlePositionAdjustment(UIOffsetMake(-1000, 0), for:UIBarMetrics.default)
因此可能是您的问题已解决。
快乐的编码。