[英]how to adjust y-axis of back button in iOS
I have created a custom navigation controller subclassing UINavigationController
. 我创建了一个自定义导航控制器子类UINavigationController
。 now when i increase the size of navigation bar then the back button also slides down. 现在,当我增加导航栏的大小时,后退按钮也会向下滑动。 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)
I am able to adjust the y axis of title by below code 我可以通过下面的代码调整标题的y轴
self.navigationBar.setTitleVerticalPositionAdjustment(-30, for: .default)
Try - (void)setBackButtonTitlePositionAdjustment:(UIOffset)adjustment forBarMetrics:(UIBarMetrics)barMetrics; 尝试 - (void)setBackButtonTitlePositionAdjustment :( UIOffset)调整BarMetrics:(UIBarMetrics)barMetrics; - (void)setBackButtonBackgroundVerticalPositionAdjustment:(CGFloat)adjustment forBarMetrics:(UIBarMetrics)barMetrics; - (void)setBackButtonBackgroundVerticalPositionAdjustment:(CGFloat)调整BarMetrics:(UIBarMetrics)barMetrics;
This works in Swift 3 这适用于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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.