如何从设备位置的起点设置后退按钮x位置?

static func backButton(navigationItem: UINavigationItem) {
        //Back Button
        let btnBack = UIButton(frame: CGRect(x: 0, y: 0, width: 40, height: 22))
        btnBack.setImage(UIImage(named:"icn-back"), for: .normal)
        btnBack.addTarget(self, action: #selector(NavBar.backBtn), for: .touchUpInside)
        let leftBtn = UIBarButtonItem.init(customView: btnBack)
        leftBtn.tintColor = UIColor(red: 30/255, green: 104/255, blue: 140/255, alpha: 1)
        navigationItem.setLeftBarButton(leftBtn, animated: false)
    }

最佳答案

let leftView = UIView(frame: CGRect(x: desiredXValue, y: 0, width: 90, height: 21))
let leftButton = UIButton(frame: CGRect(x: 0, y: 0, width: 80, height: 10))
leftButton.setImage(UIImage(named: "Group.png"), for: UIControlState())
leftButton.addTarget(self, action: #selector(ViewController.action(_:)), for: UIControlEvents.touchUpInside)
leftButton.contentMode = .scaleAspectFit
leftView.addSubview(leftButton)
leftView.contentMode = .scaleAspectFit
let leftBarButton = UIBarButtonItem(customView: leftButton)
self.navItem.leftBarButtonItem = leftBarButton
UserDefaults.standard.synchronize()

关于ios - 如何从设备位置的起点设置后退按钮x位置?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49690649/

10-09 09:25