我通过SnapKit将以下约束应用于我的Cell,它们工作得很好。
self.imageView.snp.makeConstraints { make in
make.leading.top.trailing.equalToSuperview()
make.bottom.equalTo(self.nameLabel.snp.top)
if let width = self.imageView.image?.size.width {
make.height.equalTo(width)
}
}
self.nameLabel.snp.makeConstraints { make in
make.leading.trailing.equalToSuperview()
make.top.equalTo(self.imageView.snp.bottom)
make.bottom.equalTo(self.priceLabel.snp.top)
}
self.priceLabel.snp.makeConstraints { make in
make.top.equalTo(self.nameLabel.snp.bottom)
make.leading.trailing.bottom.equalToSuperview()
}
但当我试图在两者之间增加空间时
imageView
以及
nameLabel
我有错误
self.productImageView.snp.makeConstraints { make in
make.leading.top.trailing.equalToSuperview()
make.bottom.equalTo(self.productNameLabel.snp.top).inset(-8) // change here
if let width = self.productImageView.image?.size.width {
make.height.equalTo(width)
}
}
self.productNameLabel.snp.makeConstraints { make in
make.leading.trailing.equalToSuperview()
make.top.equalTo(self.productImageView.snp.bottom).offset(8) // change here
make.bottom.equalTo(self.productPriceLabel.snp.top)
}
self.productPriceLabel.snp.makeConstraints { make in
make.top.equalTo(self.productNameLabel.snp.bottom)
make.leading.trailing.bottom.equalToSuperview()
}
我不明白的是,如果我将约束中的负移到其他8个,那么错误就会消失,但视图现在会重叠。我觉得我错过了一些基本的东西,但不知道是什么。
以下是我所希望的: