Swift - Button Image size is not downscaling

Viewed 33

Swift is not downscaling my image to fit to AspectFit and is at pre-downscaled size. Links to pictures are provided.

@objc private func didDoubleTap(_ gesture: UITapGestureRecognizer) {
        let likedImage = UIImage(named: "likedImage")
        likeButton.setImage(likedImage, for: .normal)
        likeButton.contentMode = .center //344 436 50 50
        likeButton.imageView?.contentMode = .scaleAspectFit
    }

before double tapping

enter image description here

after double tapping

enter image description here

1 Answers

You have to set the size of with and height then

just add the imageEdgeInsets

button.imageEdgeInsets = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
Related