首页 > 解决方案 > 选择拟合拟合内容模式时,UIImageView在UitableView单元格中留下了重要的空格

问题描述

在此处输入图像描述 我将 UIImageView 与内容模式 AspectFit 一起使用,但我的 url 图像在顶部和底部留下了空白区域。

我已经尝试过使用比例填充和方面填充模式,但它不能按要求工作。

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

        let row = indexPath.row

        if(row == 0){

          let cell  = tableView.dequeueReusableCell(withIdentifier: "PostNewCellIdentifier", for: indexPath) as! PostNewTableViewCell

            cell.postTitleLbl.text = commonContentList[0].commonTitle
            cell.postDateLbl.text = commonContentList[0].commonCreatedAt
           return cell


        }else if(row == 1){
            let  cell = tableView.dequeueReusableCell(withIdentifier: "PostNewSecondTableViewCellIdentifier", for: indexPath) as! PostNewSecondTableViewCell

            cell.logoURL = commonContentList[0].commonImage


             return cell
        }else if(row == 2) {

            let  cell = tableView.dequeueReusableCell(withIdentifier: "PostNewThirdTableViewCellIdentifier", for: indexPath) as! PostNewThirdTableViewCell
            cell.postDescLbl.text = postDescription

            return cell
      }
}

标签: iosswift

解决方案


ImageView如果你没有,首先设置大小约束。然后切换到Scale to Fill,并在 Attributes Inspector 中选中Clips to Bounds框。


推荐阅读