Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIImageView Scale to fill does not clip subviews

I am trying to add some images to my UIImageView. Everything works fine if the png has the same size as the ImageView.

But when I insert a bigger image, it is not discarded.

This is my code:

@IBOutlet weak var PictureView: UIImageView!

func loadSomePicture() {
    var examplePicture = UIImage(named: "Block.png")
    PictureView.image = exampleProfilePicture
    PictureView.layer.cornerRadius = 50
    PictureView.clipsToBounds = true

Althoug the clipsToBounds property is set true and the View Mode is Scale to fill, the image stays in its original size.

Thanks for Your help!

like image 500
McLawrence Avatar asked Aug 06 '14 15:08

McLawrence


2 Answers

check Clip Subviews in Drawing options

like image 71
AndrewK Avatar answered Oct 21 '22 15:10

AndrewK


I believe the problem is occurring because you are setting the contentMode to "Aspect Fill", instead of "Scale To Fill". Can you maybe explain a little more what you want the ImageView and Image to end up as? "Aspect Fill" will always try and keep the image's aspect ratio while filling it to the ImageView's size dimensions.

like image 30
ObiJacobi Avatar answered Oct 21 '22 13:10

ObiJacobi