【问题标题】:UICollectionViewCell: how to have each cell with different namingUICollectionViewCell:如何让每个单元格具有不同的命名
【发布时间】:2017-11-30 18:01:59
【问题描述】:

我想让我的单元格具有不同的标题,但它始终显示相同的所有 我尝试使用二维数组但并不真正知道如何实现它

任何帮助将不胜感激,

class DequedCEll: UICollectionViewCell {
    override init(frame: CGRect) {
        super.init(frame: frame)
    setupViews()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

// this is the part where i stuck 

    let Mainlabel : UILabel = {
        var label = UILabel()
        label.text = "??"
        label.font = UIFont.boldSystemFont(ofSize: 45)

       return label
    }()

    func setupViews () {

        backgroundColor = .yellow
        addSubview(Mainlabel)

        Mainlabel.anchorToTop(self.topAnchor, left: self.leftAnchor, bottom: self.bottomAnchor, right: self.rightAnchor)

    }


}

【问题讨论】:

    标签: ios uilabel uicollectionviewcell


    【解决方案1】:

    我假设您在代码中的某处将collectionViewCell 出列。您可以在出列单元格后立即设置标签。

    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: yourCellIdentifier, for: indexPath) as? DequedCEll else { return DequedCEll() }
    
        cell.Mainlabel.text = "your text here from you array, probably using indexPath to determine what text to use"
        return cell
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-07-10
      • 2013-11-15
      • 1970-01-01
      • 1970-01-01
      • 2023-04-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多