我正在尝试添加导航项右栏按钮。一切正常,但我想添加这个酒吧按钮项目更接近正确的地方。任何方式来改变右键项目的位置。
我尝试使用按钮框更改它,但它无法正常工作
这是我的代码:
let userPhoto = UIButton()
userPhoto.setImage(UIImage(named: "user"), forState: .Normal)
userPhoto.frame = CGRectMake(0, 0, 42, 42)
userPhoto.layer.cornerRadius = userPhoto.frame.size.width / 2;
userPhoto.layer.masksToBounds = true;
userPhoto.addTarget(self, action: #selector(userEdit), forControlEvents: .TouchUpInside)
let userPhotoItem = UIBarButtonItem()
userPhotoItem.customView = userPhoto
let phonePhoto = UIButton()
phonePhoto.setImage(UIImage(named: "user"), forState: .Normal)
phonePhoto.frame = CGRectMake(0, 0, 30, 30)
phonePhoto.addTarget(self, action: #selector(userEdit), forControlEvents: .TouchUpInside)
let userPhone = UIBarButtonItem()
userPhone.customView = phonePhoto
self.navigationItem.rightBarButtonItems = [userPhotoItem, userPhone]
答案 0 :(得分:0)
我找到了答案,也许有人想要使用它。
增加了空间:
let space = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.FixedSpace, target: nil, action: nil)
space.width = -10.0
self.navigationItem.rightBarButtonItems = [space, userPhotoItem, userPhone]