Lasse Bickmann
Lasse Bickmann

Reputation: 133

Swift - cornerRadius on Image doesn't work

In my tableviews custom cell I have an image:

Image of my tableview

I want to get the cornerRadius = 20. But for some reason it won't work I have used this code:

cell.offerImage.layer.cornerRadius = 20
cell.offerImage.clipsToBounds = true

And the Imageviews content mode is Aspect Fit. It is funny, because I tried to play around with it, and when I used:

cell.offerImage.layer.cornerRadius =  cell.offerImage.frame.size.width / 2

I got some weird cornerRadius, not the round as I expected. It is like the cornerRadius is on the imageView and not the image, and I dont know the precise size of the image (uploaded from server).

Upvotes: 1

Views: 3168

Answers (2)

Sandip Mane
Sandip Mane

Reputation: 1623

This is working for me I am have checked clipsToBound in the .xib file

imageView.layer.cornerRadius = 50

Upvotes: 1

Mickael Belhassen
Mickael Belhassen

Reputation: 3342

You need to add

imageView.clipsToBounds = true

Upvotes: 0

Related Questions