All the answers above couldn't solve the problem in my case. My ImageView
was placed in a customized UITableViewCell
. Therefore I had also call the layoutIfNeeded()
method from here. Example:
class NameTableViewCell:UITableViewCell,UITextFieldDelegate { ...
override func awakeFromNib() {
self.layoutIfNeeded()
profileImageView.layoutIfNeeded()
profileImageView.isUserInteractionEnabled = true
let square = profileImageView.frame.size.width < profileImageView.frame.height ? CGSize(width: profileImageView.frame.size.width, height: profileImageView.frame.size.width) : CGSize(width: profileImageView.frame.size.height, height: profileImageView.frame.size.height)
profileImageView.addGestureRecognizer(tapGesture)
profileImageView.layer.cornerRadius = square.width/2
profileImageView.clipsToBounds = true;
}