0

I can add some padding to my rightbarbuttonitem(eye icon) with the following codes but the result is slightly different on other devices. You can see in the image.

    let add = UIBarButtonItem(image: #imageLiteral(resourceName: "open"), style: .plain, target: self, action: #selector(closeChords))
    add.tintColor = UIColor.black
    add.imageInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: -8)
    
    self.navigationItem.rightBarButtonItem = add

ss of simulators

portable
  • 11
  • 3

1 Answers1

0

I think its for the device sizes and the different icon sizes too.

In this link explain it, the different icon sizes and how it used by the device.

iOS navigation bar item image size

Another way, maybe this code help you

let customButton = UIButton.init(frame: CGRect.init(x: 0, y: 0, width: 30, height: 30))
    customButton.setImage(UIImage.init(named:"imageName"), for: .normal)
    self.navigationItem.rightBarButtonItem = UIBarButtonItem.init(customView: customButton)
Diego Cruz
  • 36
  • 1