I'm trying to apply a radius to the corner of the images showed in a table to make them look like a circle. The problem is that the images are located via autolayout, so the final size is not calculated till the view has layout all its subviews, and I need to code the circle mask after that.

The solution that came to me was to write the code inside the method tableView(... willDisplayCell ...), or inside the methods didMoveToSuperview() and layoutSubviews() on the custom UITableViewCell subclass. I have seen this solutions on some questions of this forum, but no one of them are working.

Here is the code with one of those methods commented:

```
import UIKit

struct Contact {
    var name: String
    var image: UIImage
}

class ActiveChatsController: UITableViewController {

    let contacts = [
        Contact(name: "Alex", image: UIImage(named: "Alex")!),
        Contact(name: "Puto Albert", image: UIImage(named: "Albert")!),
        Contact(name: "Golfo-man", image: UIImage(named: "Pablo")!)
    ]

    override func viewDidLoad() {
        self.navigationController!.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: AppDesign.color(withIntensity: 6)]
    }

    override func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return contacts.count
    }

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = Bundle.main.loadNibNamed("OpenedChatCell", owner: self, options: nil)?.first as! OpenedChatCell
        cell.contactImage.image = contacts[indexPath.row].image
        cell.contactName.text = contacts[indexPath.row].name

        return cell
    }

}

```

And the custom cell subclass is got from a XIB file:

```
import UIKit

class OpenedChatCell: UITableViewCell {

    @IBOutlet weak var contactImage: UIImageView!
    @IBOutlet weak var contactName: UILabel!

    /*
    override func didMoveToSuperview() {
        self.contactImage.layer.cornerRadius = self.contactImage.frame.width / 2
        self.contactImage.clipsToBounds = true
    }
     */

}

```

If I run these codes on the simulator, I get this:

[![enter image description here](https://i.stack.imgur.com/oW3wp.png)](https://i.stack.imgur.com/oW3wp.png)

But if I delete the comments on the didMoveToSuperview() method and let it change the radius I get this:

[![enter image description here](https://i.stack.imgur.com/Lw3fN.png)](https://i.stack.imgur.com/Lw3fN.png)

After this, I wrote inside didMoveToSuperview():

```
print(self.contactImage.frame.height)

```

And it shows a height of 177.0, so I don't know where the error may be.