I have this code for my UIBarButtonItem. When i’m trying with title, everything is ok, but with image it shows a little bit left then it should be. I don’t know how to fix it, what can be wrong? Same problem if i do leftBarButtonItem.
navigationItem.rightBarButtonItem = UIBarButtonItem(title: "123", style: .done, target: self, action: #selector(toggleInterfaceStyle))
navigationItem.rightBarButtonItem = UIBarButtonItem(image: #imageLiteral(resourceName: "day"), style: .done, target: self, action: #selector(toggleInterfaceStyle))
2
Answers
This code could help you in terms of padding:
Width must be positive in Swift version
Also you can use insets:
I had the same issue, and there’s a neat trick you can do with a UIBarButtonSystemItemFixedSpace, add one of these with a negative width before your first button and after your last button and it will move the button to the edge
let negativeSeperator = UIBarButtonItem(barButtonSystemItem: .fixedSpace, target: nil, action: nil)
negativeSeperator.width = 12