iOS swift UICollectionView

1.纯代码自定义UICollectionViewCell

import UIKit

class 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 = newUIBlack
        contentView.addSubview(topImageView)
        topImageView.snp.makeConstraints {
    
     make in
            make.top.equalToSuperview().offset(10)
            make.width.height.equalTo(25)
            make.centerX.equalToSuperview()
        }
        
        contentView.addSubview(bottomLabel)
        bottomLabel.textColor = .white
        bottomLabel.snp.makeConstraints {
    
     make in
            make.centerX.equalToSuperview()
            make.top.equalTo(topImageView.snp_bottom).offset(10)
            
        }
        
    }
    
    func reloadData(){
    
    
        bottomLabel.text = "平均速度"
        topImageView.image = UIImage(named: model.image)
    }
}

参考博客:
Swift之自定义UICollectionViewCell - csdn

2.禁止滑动(弹簧效果)

        collectionView.bounces = false

参考博客:
iOS swift-UIScrollview,UITableview,UICollectionView单独禁止下拉(上拉)

3.UICollectionView的长按拖动

参考博客:
Swift下使用UICollectionView 实现长按拖拽功能

2.在一个控制器中放两个UICollectionView或者UITableView,代理方法要怎么写

猜你喜欢

转载自blog.csdn.net/baidu_40537062/article/details/129226764