简体   繁体   中英

how to adjust y-axis of back button in iOS

I have created a custom navigation controller subclassing 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

self.navigationBar.setTitleVerticalPositionAdjustment(-30, for: .default)

Try - (void)setBackButtonTitlePositionAdjustment:(UIOffset)adjustment forBarMetrics:(UIBarMetrics)barMetrics; - (void)setBackButtonBackgroundVerticalPositionAdjustment:(CGFloat)adjustment forBarMetrics:(UIBarMetrics)barMetrics;

This works in 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)

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM