自定义UITableViewCell中的UIImageView在单击时调整大小

时间:2019-06-27 10:36:40

标签: swift uitableview uiimageview

我有一个自定义的UI表格视图单元格,单击它时,单元格内的UIImageView会调整大小,并且在单击时会丢失cellForRowAt中定义的先前样式(例如,圆角)。请查看所附图片。enter image description here

代码引用cellForRowAt中的个人资料图像视图

  cell.profileImageView.layer.masksToBounds = false
        cell.profileImageView.layer.cornerRadius = cell.profileImageView.frame.height/2
        cell.profileImageView.clipsToBounds = true

didSelectRow中的代码

let message = downloadedmessages![indexPath.row] as! ALMessage

let displayVC : ChatViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "chatViewController") as! ChatViewController
displayVC.sender = msgUser(senderId: ALUserDefaultsHandler.getUserId(), displayName: ALUserDefaultsHandler.getDisplayName())
displayVC.reciever = msgUser(senderId: message.to, displayName: message.name)
navigationController?.pushViewController(displayVC, animated: true)
}

1 个答案:

答案 0 :(得分:0)

尝试添加contentMode中的profileImageView,即

profileImageView.contentMode = .scaleAspectFit

还要在height的{​​{1}}中添加适当的widthconstraints profileImageView

注意:如果您要重用同一单元格,则.xib并不是添加单元格tableView(_:cellForRowAt:)属性的正确位置。必须在layer方法中添加,即

awakeFromNib()