Created
July 2, 2018 08:31
-
-
Save sonnguyen0310/6720cbf39ce877c20fea1a987543fb99 to your computer and use it in GitHub Desktop.
iOS 11: Change size of UIBarButtonItem (image) in Swift 3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You save my time. Thank you so much :)