TrevPennington
TrevPennington

Reputation: 475

Swift UIKit how to masksToBounds for image view

My parent view has rounded corners on all sides and I would like the child image view to have rounded corners on the right-top and right-bottom to fit inside the parent view. Swift documentation says masksToBounds will solve this, but it does not work for me. As seen in the photo, the right side of the photo is not rounded on the right side. Let me know if you would like to see more of my code, thank you.

Here is my code:

            bottomViewThumbnailImageView.translatesAutoresizingMaskIntoConstraints = false
            bottomViewThumbnailImageView.clipsToBounds = true
            bottomViewThumbnailImageView.layer.masksToBounds = true

            
            NSLayoutConstraint.activate([
                bottomViewThumbnailImageView.topAnchor.constraint(equalTo: bottomView.topAnchor),
                bottomViewThumbnailImageView.bottomAnchor.constraint(equalTo: bottomView.bottomAnchor),
                bottomViewThumbnailImageView.trailingAnchor.constraint(equalTo: bottomView.trailingAnchor),
                bottomViewThumbnailImageView.heightAnchor.constraint(equalTo: bottomViewThumbnailImageView.widthAnchor),
            ])

enter image description here

Upvotes: 0

Views: 264

Answers (2)

Shehata Gamal
Shehata Gamal

Reputation: 100503

The property should be set for the imageView parent as it will flow to it's childs , setting it to the imageView itself has no effect

parentImg.clipsToBounds = true

Upvotes: 1

achu
achu

Reputation: 329

Try giving this for your cell

layer.masksToBounds = true

Upvotes: 1

Related Questions