import UIKitclass NewDeviceBottomCollectionViewCell: UICollectionViewCell {var model:NewBottomModel = NewBottomModel(image: "海拔", text: "test") {didSet{reloadData()}}override init(frame: CGRect) {super.init(frame: frame)setupUI()}required init?(coder: NSCoder) {fatalError("init(coder:) has not been implemented")}var bottomLabel = UILabel()var topImageView = UIImageView()func setupUI(){contentView.backgroundColor = newUIBlackcontentView.addSubview(topImageView)topImageView.snp.makeConstraints { make inmake.top.equalToSuperview().offset(10)make.width.height.equalTo(25)make.centerX.equalToSuperview()}contentView.addSubview(bottomLabel)bottomLabel.textColor = .whitebottomLabel.snp.makeConstraints { make inmake.centerX.equalToSuperview()make.top.equalTo(topImageView.snp_bottom).offset(10)}}func reloadData(){bottomLabel.text = "平均速度"topImageView.image = UIImage(named: model.image)}
}
参考博客:
Swift之自定义UICollectionViewCell - csdn
collectionView.bounces = false
参考博客:
iOS swift-UIScrollview,UITableview,UICollectionView单独禁止下拉(上拉)
参考博客:
Swift下使用UICollectionView 实现长按拖拽功能