Circular Image Becoming a Diamond Not Circle - Swi

2019-02-26 05:22发布

问题:

I have been trying to create a circular image but for some reason it has been outputting as a diamond. This is my code:

override func viewDidLoad() {
    displayEmailFullNameImage()

    self.editProfilePictureImage.layer.cornerRadius = editProfilePictureImage.frame.size.width / 2
    self.editProfilePictureImage.clipsToBounds = true
    self.editProfilePictureImage.contentMode = .scaleAspectFill

}

My Constraints on the photo:

I have tried the following solution:

override func viewWillLayoutSubviews() {
    super.viewWillLayoutSubviews()
    profilePic.layer.cornerRadius = profilePic.frame.width / 2
    profilePic.clipsToBounds = true
}

BUT this does not work either.

This is how the image looks:

Any help would be appreciated.

回答1:

Your problem it is probably caused by some constraints you have added to your imageView. Try adding only 4 constraints, 1 for fixed width, 1 for fixed height, 1 for leading space and 1 for top space as you can see at the screenshot below: