6

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!

McLawrence
  • 4,975
  • 7
  • 39
  • 51

2 Answers2

4

check Clip Subviews in Drawing options

AndrewK
  • 907
  • 8
  • 14
  • 1
    This simple answer worked for me. I had an imageView with Scale To Fill and the cornerRadius wasn't working until I checked the "Clip Subviews" in Drawing options. Thanks! – Doug Voss Sep 02 '15 at 17:25
3

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.

ObiJacobi
  • 46
  • 2
  • Changing the Mode to Scale To Fill hasn't changed anything in the appearence. I want a round image with a radius of 50. If I add an image bigger than 100x100, I haven't got a circle anymore but a bigger square with rounded corners. – McLawrence Aug 06 '14 at 15:55
  • When I have the contentMode set to Scale to Fill the image scales to the size of the imageView can you post screenshots or more code? For example I have a imageView of size 200x200 and an image of 465x500 and the image scales down and is a circle – ObiJacobi Aug 06 '14 at 16:32
  • Somehow now it works, after deleting the old ImageView and connecting the code to a new one... – McLawrence Aug 07 '14 at 09:00
  • Well Im glad that it works, good luck on the rest of your code! – ObiJacobi Aug 07 '14 at 12:28