Search code examples
iosswiftuitableviewuiimageview

Swift: Image view display wrong


I have UIImageView with constraint look like picture TableviewCell

but when set image from array Data, it's display wrong (outside of imageView) Image display wrong

i've set in tableView

cell.imgView.contentMode = .scaleAspectFill
cell.imgView.clipsToBounds = true
if self.arrDulieu[indexPath.row].attachment?.count ?? 0 > 0 {
   cell.imageView!.image = UIImage(data: self.arrDulieu[indexPath.row].attachment![0])
}

Solution

  • It should be imgView (property of the custom class) not imageView (property of the UITableViewCell class)

    cell.imgView.image = UIImage(data: self.arrDulieu[indexPath.row].attachment![0])