我创建了一个自定义导航控制器子类UINavigationController
。现在,当我增加导航栏的大小时,后退按钮也会向下滑动。 Then how to adjust the y-axis of back button.
self.navigationBar.frame = CGRect(x:0, y: 20, width: self.view.frame.size.width, height: 64.0)
我可以通过以下代码
调整标题的y轴self.navigationBar.setTitleVerticalPositionAdjustment(-30, for: .default)
答案 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)