我正在尝试制作一个具有3个图像尺寸的UITableViewCell。我有一个这样的模型:
struct Model {
var image: UIImage
var imageSize: size
enum size {
case large
case medium
case small
case custom(CGFloat)
}
}
并且我有一个switch语句来调整图像的大小:
switch Model.imageSize {
case .small?:
imageView.image = Model.image?.withAlignmentRectInsets(UIEdgeInsets(top: -16, left: -16, bottom: -16, right: -16))
case .medium?:
imageView.image = Model.image?.withAlignmentRectInsets(UIEdgeInsets(top: -8, left: -8, bottom: -8, right: -8))
case .large?:
imageView.image = Model.image
case .custom(let inset)?:
imageView.image = Model.image?.withAlignmentRectInsets(UIEdgeInsets(top: -inset, left: -inset, bottom: -inset, right: -inset))
case .none:
print("Size -none")
break
}
我在setupView(for: Model)
内部的CustomCell.swift
方法中使用switch语句
我重写了prepareForReuse
方法来制作imageView.image
nil
,但是我无法解决问题。滚动后,图像可能没有插图出现。我应该怎么做才能避免这种情况?