我有一个tableView代表位置概览。每个单元/地方都有一张图片和一个邀请朋友的按钮。
现在,我想在缩略图底部添加一行以显示该点的等级(即,增加投票和减少投票):
如果将来我想更改按钮的位置或大小,我该如何尽可能动态地处理它?</ p>
环境看起来像这样,但是我不希望复制粘贴解决方案。
class tvCell: UITableViewCell {
let thumbnailImageView: UIImageView = {
let imageview = UIImageView()
imageview.contentMode = .scaleAspectFill
imageview.clipsToBounds = true
imageview.image = UIImage(named: "testbild")
imageview.layer.cornerRadius = 10
return imageview
}()
let addFriendView = GSAddFriendView()
func layout() {
let buttonSize: CGFloat = 60
self.addSubview(thumbnailImageView)
thumbnailImageView.topAnchor.constraint(equalTo: dotsButton.bottomAnchor, constant: 4).isActive = true
thumbnailImageView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 16).isActive = true
thumbnailImageView.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -16).isActive = true
thumbnailImageView.heightAnchor.constraint(equalTo: thumbnailImageView.widthAnchor, multiplier: 9/16).isActive = true
self.addSubview(addFriendView)
addFriendView.topAnchor.constraint(equalTo: thumbnailImageView.bottomAnchor, constant: buttonSize/2 + 10).isActive = true
addFriendView.widthAnchor.constraint(equalToConstant: buttonSize).isActive = true
addFriendView.heightAnchor.constraint(equalToConstant: buttonSize).isActive = true
addFriendView.centerXAnchor.constraint(equalTo: centerXAnchor, constant: 0).isActive = true
}
}