Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
iOS 11: Change size of UIBarButtonItem (image) in Swift 3
func setUpMenuButton(){
let menuBtn = UIButton(type: .custom)
menuBtn.frame = CGRect(x: 0.0, y: 0.0, width: 20, height: 20)
menuBtn.setImage(UIImage(named:"menuIcon"), for: .normal)
menuBtn.addTarget(self, action: #selector(vc.onMenuButtonPressed(_:)), for: UIControlEvents.touchUpInside)
let menuBarItem = UIBarButtonItem(customView: menuBtn)
let currWidth = menuBarItem.customView?.widthAnchor.constraint(equalToConstant: 24)
currWidth?.isActive = true
let currHeight = menuBarItem.customView?.heightAnchor.constraint(equalToConstant: 24)
currHeight?.isActive = true
self.navigationItem.leftBarButtonItem = menuBarItem
}
@L4grange

This comment has been minimized.

Copy link

@L4grange L4grange commented Jan 13, 2019

Thank you so much! My UIBarButtonItem with a custom settings icon was too wide for some unexplained reason (the PDF icon was a square) and this was the only way to get it to the correct size.

@heybetzadec

This comment has been minimized.

Copy link

@heybetzadec heybetzadec commented Mar 7, 2019

Thanks man!

@krmao

This comment has been minimized.

Copy link

@krmao krmao commented Sep 11, 2019

great

@updev0612

This comment has been minimized.

Copy link

@updev0612 updev0612 commented Jan 18, 2020

Really thank you.
I lost whole night for this.
But your code save me from risk.
Thank you again.

@PredragJ

This comment has been minimized.

Copy link

@PredragJ PredragJ commented Jan 23, 2020

Thanks man. I lost to much time for this! Cheers!

@pradeepktg

This comment has been minimized.

Copy link

@pradeepktg pradeepktg commented Feb 7, 2020

Thank you so much! I was going mad resolving this issue. Cheers!!!

@Kanokchai-ama

This comment has been minimized.

Copy link

@Kanokchai-ama Kanokchai-ama commented Sep 17, 2020

Thank you so much man. 🤝

@Scankiran

This comment has been minimized.

Copy link

@Scankiran Scankiran commented Nov 7, 2020

Thanks man. You save me a lot work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.