R
R
rejjer2017-09-30 12:21:13
iOS
rejjer, 2017-09-30 12:21:13

How to change position of UIBarButtonItem icon in iOS11?

I use icons from SwiftIcons (vector, IMHO, is better than multiple images for different resolutions @1-3, or am I wrong?).
I'm adding a custom 'back' arrow, if I just put the icon in the navbar it won't show where the same icon is by default, so I add a fixedSpace with a negative width:

let manuButton = UIBarButtonItem()
manuButton.setIcon(icon: .ionicons(.chevronLeft), iconSize: 24, color: .white, cgRect: CGRect(x: 0, y: 0, width: 24, height: 24), target: self, action: #selector(menuButtonClick))
let negativeSpacer:UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.fixedSpace, target: nil, action: nil)
negativeSpacer.width = -13.7;
self.navigationItem.leftBarButtonItems = [negativeSpacer, manuButton]

Before iOS11 everything worked, but now it doesn't want to apply negative width:
5HxXW.png
How can I fix this issue?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
rejjer, 2017-09-30
@rejjer

You can add indents to the button if the icon is inserted as a picture for UIBarButtonItem

let menuButton = UIBarButtonItem(title: "", style: .plain, target: self, action: #selector(menuButtonClick))
menuButton.image = UIImage.init(icon: .ionicons(.chevronLeft), size: CGSize(width: 24, height: 24))
menuButton.imageInsets = UIEdgeInsetsMake(0, -13.7, 0, 0)
self.navigationItem.leftBarButtonItem = menuButton

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question