Reputation: 142
I created button for navbar with custom image and want to change its tint color each time user taps on it.
let addToFavoritesButton = UIImage(systemName: SystemImages.FilledStar.rawValue)
navigationItem.rightBarButtonItem = UIBarButtonItem(image: addToFavoritesButton, style: .plain, target: self, action: #selector(addOrRemoveFromFavorites))
navigationItem.rightBarButtonItem?.tintColor = presenter.addToFavoriteButtonColor()
Upvotes: 0
Views: 54
Reputation: 131
You should put this the change of the rightBarButtonItem tint color inside the function you created for the tap on the rightBarButtonItem
@objc func addOrRemoveFromFavorites(_ sender: AnyObject) {
navigationItem.rightBarButtonItem?.tintColor =
presenter.addToFavoriteButtonColor()
}
this will only work if you have a UINavigationController.
Upvotes: 1