解决导航栏,添加按钮,布局右移的问题
let spaceButtonItem = UIBarButtonItem.init(barButtonSystemItem: .fixedSpace, target: self, action: nil);
spaceButtonItem.width = -15;
let leftBtn = UIButton.init(type: .custom);
leftBtn.setTitle("返回", for: .normal);
leftBtn.setImage(UIImage.init(named: "icon_back"), for: .normal);
leftBtn.setTitleColor(UIColor.black, for: .normal);
leftBtn.frame = CGRect(x: -20, y: 0, width: 60, height: 44)
let leftItem = UIBarButtonItem.init(customView: leftBtn);
leftItem.width = -15;
leftItem.style = UIBarButtonItemStyle.plain;
leftBtn.addTarget(self, action: #selector(gobackVC(sender:)), for: .touchUpInside);
// self.navigationItem.leftBarButtonItem = leftItem
self.navigationItem.leftBarButtonItems = [spaceButtonItem,leftItem];
let spaceButtonItem1 = UIBarButtonItem.init(barButtonSystemItem: .fixedSpace, target: self, action: nil);
spaceButtonItem1.width = -15;
let rightBTN = UIButton.init(type: .custom);
rightBTN.setTitle("关闭", for: .normal);
rightBTN.setTitleColor(UIColor.black, for: .normal);
// rightBTN.setImage(UIImage.init(named: "iconz-add_photo"), for: .normal);
rightBTN.imageView?.contentMode = .center;
rightBTN.frame = CGRect(x: 20, y: 0, width: 60, height: 40)
rightBTN.addTarget(self, action: #selector(dismissVC(sender:)), for: .touchUpInside);
let rightItem = UIBarButtonItem.init(customView: rightBTN);
self.navigationItem.rightBarButtonItems = [spaceButtonItem1,rightItem];
注:leftItem.width = -15; 可以根据具体情况调整
网友评论