0

I am working on favourites in swift, on favourites button click I want to change the image of the button from star to star.fill which are system images, I put on main story board the star image and in my code I want onClick favoris button to change the image into star.fill, there is my code

  @IBAction func add Favoris(_ sender: Any) {
        favoris_ button. imageView?.image = UIImage(systemName: "star.fill")

        }

But it doesn't work, any help please?

vijeesh
  • 1,317
  • 1
  • 17
  • 32
Yafet Shil
  • 41
  • 7
  • Check this. https://stackoverflow.com/questions/26837371/how-to-change-uibutton-image-in-swift – Abhishek Patel Dec 17 '19 at 10:15
  • in that example they are working on image assets, but what I want to work with is system images, but thank you for your help :) – Yafet Shil Dec 17 '19 at 10:23
  • Does this answer your question? [How to change UIButton image in Swift](https://stackoverflow.com/questions/26837371/how-to-change-uibutton-image-in-swift) – dandan78 Dec 17 '19 at 11:46
  • already resolved, check Tanjima's answer, thank you at anyways :) – Yafet Shil Dec 17 '19 at 12:47

1 Answers1

1
@IBAction func addFavoris(_ sender: Any) {
        if #available(iOS 13.0, *) {
            favoris_button.setImage(UIImage(systemName: "star.fill"), for: .normal)
        } else {
            // Fallback on earlier versions
        }
    }
Tanjima Kothiya
  • 5,695
  • 2
  • 8
  • 17