I am trying to change the size of some icons in my navBar, but I am a little confused as to how to do this? My code so far is:
func setUpNavBarButtons() {
let moreButton = UIBarButtonItem (image: UIImage(named:"ic_more_vert_3")?.withRenderingMode(.alwaysOriginal), style: .plain, target: self, action: #selector(handleMore))
navigationItem.rightBarButtonItems = [moreButton]
let refreshButton = UIBarButtonItem (image: UIImage(named:"ic_refresh")?.withRenderingMode(.alwaysOriginal), style: .plain, target: self, action: #selector(refreshDataButton))
navigationItem.leftBarButtonItems = [refreshButton]
}
any help?
In the end I did it like this and it worked:
Answer from: Change width of a UIBarButtonItem in a UINavigationBar in swift
You can configure the frame of you button like below:
You can configure the bar buttons using this function:
And You can init the custom view as You desire. After that You can access the view if needed via
UIBarButtonItem
's:Hint: Because
UIButton
is a child class ofUIView
, You can directly use it too.@DogCoffee answer is a great and creative way to solve the problem. May I suggest some slightly mods in order to take into account size and tintColor
Extension for Swift 4.2
Just a different way of implementation the answer provided by anoop4real
However using button type
.system
allows the global tint to be applied to your iconUsage:
Implementation:
This is how I did it
iOS 10 and below
iOS 11 - Navigation bar come up with Autolayout so frame setting may not work