【问题标题】:iOS UITableViewCell with UIImageView display image outside the viewiOS UITableViewCell 和 UIImageView 在视图外显示图像
【发布时间】:2021-10-17 08:12:44
【问题描述】:

我有一个UITableViewCell,其中有一个UIImageView,图像占位符工作得很好,但是当使用SDWebImage从带有实际数据的url获取图像时,图像将显示在UIImageView之外。

我尝试过使用以下方法,但没有任何效果。

cell.imageView?.contentMode = .scaleAspectFit
cell.imageView?.clipsToBounds = false
cell.imageView?.layer.masksToBounds = true

我已附上参考图片以进一步了解。

UITableViewCell

我也尝试将图像从服务器调整为 40 x 40,但仍然是同样的问题。

//cell.imageView?.sd_setImage(with: URL(string: "\(Constants.string.WEB)/assets/\(dict.image)"), placeholderImage: UIImage(named: Constants.string.IMAGE_PLACEHOLDER_60))
                
cell.imageView?.sd_setImage(with: URL(string: "\(Constants.string.WEB)/assets/\(dict.image)")) { (image, error, cache, urls) in
   if error != nil {
      cell.imageView?.image = UIImage(named: Constants.string.IMAGE_PLACEHOLDER_60)!.resizeImageWith(newSize: CGSize(width: 40, height: 40))
   } else {
     cell.imageView?.image = image!.resizeImageWith(newSize: CGSize(width: 40, height: 40))
   }
}

【问题讨论】:

    标签: swift uitableview uiimageview uikit sdwebimage


    【解决方案1】:

    imageView 的大小是多少?你有没有设置任何限制?还将cell.imageView?.clipsToBounds 设置为true。确保 imageView 具有高度和宽度约束集以及前导和顶部约束集。

    【讨论】:

    • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
    • imageView 大小为 40,添加了高度和宽度约束,我还将 imageView clipsToBounds 设置为 true。我还尝试将图像大小调整为 40
    猜你喜欢
    • 2016-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多