0

I am trying to add navigation item right bar button. Everything working correctly but I want to add this bar button item more close to the right place. Any way to change the right button items place.

I tried to change it with button frame but it did not work

This is my code:

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]
kb920
  • 3,039
  • 2
  • 33
  • 44
John
  • 386
  • 1
  • 7
  • 22

1 Answers1

0

I found the answer maybe someone wants to use it.

Added space:

let space = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.FixedSpace, target: nil, action: nil)
        space.width = -10.0

self.navigationItem.rightBarButtonItems = [space, userPhotoItem, userPhone]
John
  • 386
  • 1
  • 7
  • 22