Reputation: 475
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),
])
Upvotes: 0
Views: 264
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