如何在iOS中调整后退按钮的y轴

时间:2016-11-10 11:02:43

标签: ios swift uinavigationcontroller uinavigationbar uinavigationitem

我创建了一个自定义导航控制器子类UINavigationController。现在,当我增加导航栏的大小时,后退按钮也会向下滑动。 Then how to adjust the y-axis of back button.

enter image description here

self.navigationBar.frame = CGRect(x:0, y: 20, width: self.view.frame.size.width, height: 64.0)

我可以通过以下代码

调整标题的y轴
self.navigationBar.setTitleVerticalPositionAdjustment(-30, for: .default)

2 个答案:

答案 0 :(得分:0)

尝试 - (void)setBackButtonTitlePositionAdjustment:(UIOffset)调整                                forBarMetrics:(UIBarMetrics)barMetrics; - (void)setBackButtonBackgroundVerticalPositionAdjustment:(CGFloat)调整                                             forBarMetrics:(UIBarMetrics)barMetrics;

答案 1 :(得分:0)

这适用于 Swift 3

self.navigationController?.navigationBar.frame = CGRect(x: 0, y: 20, width: self.view.bounds.size.width, height: 100)
    self.navigationController?.navigationBar.barTintColor = UIColor.yellow
    self.title = "My Title"
    self.navigationController?.navigationBar.setTitleVerticalPositionAdjustment(-30, for: .default)
    let button = UIBarButtonItem(title: "myButton", style: .done, target: self, action: #selector(myViewController.myFunc))
    self.navigationItem.leftBarButtonItem = button
    self.navigationItem.leftBarButtonItem?.setTitlePositionAdjustment(.init(horizontal: 0, vertical: -30), for: .default)

enter image description here