image has to be circular without empty spaces in swift

Viewed 45

I have a image downloaded from the web and i want to show the image in circular form.right now the image is not in circular form.It shows white spaces on top and bottom of the imageview. The code used for the image is as follows:

self.profileview.layer.cornerRadius = self.profileview.frame.height / 2
        self.profileview.layer.borderWidth = 1.0       
 self.profileview.layer.borderColor = UIColor.black.cgColor
        self.profileimg.clipsToBounds = true

The image which appears is as follows:

enter image description here

How to make the image circular?

1 Answers

try this , may be it will work in your case .

myimageview.contentMode = .scaleAspectFill

or

myimageviewcontentMode = .scaleToFill

Related