import UIKit
import Material
class MyVC: UITableViewController {
fileprivate var deleteButton: IconButton!
override func viewDidLoad() {
super.viewDidLoad()
prepareDeleteButton()
navigationItem.rightViews = [deleteButton]
}
// other delegates of UITableView
}
extension MyVC {
fileprivate func prepareDeleteButton() {
deleteButton = IconButton(image: UIImage(named: "Trash"))
deleteButton.tintColor = Color.red.base
deleteButton.addTarget(self, action: #selector(doSomething), for: .touchUpInside)
}
@objc
fileprivate func doSomething() {
print("delete accessory")
}
}
Note that MyVC
is pushed from another ViewController
.
In MyVC
, I want my trash can icon to be at the upper right corner of the screen, which is navigationItem.rightViews = [deleteButton]
, and to have red base color deleteButton.tintColor = Color.red.base
.
But it does not work in the code above, the trash can is still black. How can I change its tint color?
It seems that my trash icon is a little bigger then other Cosmic Mind icons at the same rightViews
although it has the same size as Cosmic Mind icons (24x24 @1x). Is it true? How to make it a little smaller?
Regards,
The issue with your code is that you are not using the correct rendering mode. Try this:
deleteButton = IconButton(image: UIImage(named: "Trash")!.withRenderingMode(.alwaysOriginal))
All the best!