我正在尝试更改UINavigationController
内的后退按钮。这是我到目前为止尝试的和输出:
1
ViewDidLoad
self.navigationController?.navigationBar.backIndicatorImage = UIImage(named: "navBarBackButton")
self.navigationController?.navigationBar.backIndicatorTransitionMaskImage = UIImage(named: "navBarBackButton")
self.navigationItem.backBarButtonItem?.image = UIImage(named: "navBarBackButton")
输出:
我尝试添加以下内容,但ID没有帮助:
self.navigationItem.backBarButtonItem = UIBarButtonItem(title:"", style:.Plain, target:nil, action:nil)
2
AppDelegate
let backImg: UIImage = UIImage(named: "navBarBackButton")!
UIBarButtonItem.appearance().setBackButtonBackgroundImage(backImg, forState: .Normal, barMetrics: .Default)
输出:
3
我尝试在Storyboard
中添加后退按钮,但没有改变
4 - 感谢sanandiya vipul。仍然需要它而不是' Back'。这只会删除“后退”,但会将图像保持在右下方而不是整个“后退”。
UIBarButtonItem.appearance().setBackButtonTitlePositionAdjustment(UIOffsetMake(0, -80.0), forBarMetrics: .Default)
这是输出:
这是我希望实现的结果
答案 0 :(得分:5)
Swift
UIBarButtonItem.appearance()。setBackButtonTitlePositionAdjustment(UIOffsetMake(0,-80.0),forBarMetrics:.Default)
Objective-c
[[UIBarButtonItem外观] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, - 80.f)forBarMetrics:UIBarMetricsDefault];
答案 1 :(得分:1)
Swift 4版本
将标题文字颜色设置为清除
let barButtonItemAppearance = UIBarButtonItem.appearance()
barButtonItemAppearance.setTitleTextAttributes([NSAttributedStringKey.foregroundColor: UIColor.clear], for: .normal)
barButtonItemAppearance.setTitleTextAttributes([NSAttributedStringKey.foregroundColor: UIColor.clear], for: .highlighted)
答案 2 :(得分:0)
Swift 3版本
UIBarButtonItem.appearance()。setBackButtonTitlePositionAdjustment(UIOffsetMake(0, -80.0),用于:.default)
答案 3 :(得分:-1)
刚刚添加了UIBarButtonItem
并将其与行动相关联。
@IBAction func backTapped(sender: AnyObject) {
self.navigationController?.popViewControllerAnimated(true)
}