2017-11-30 5 views
0
내가 다른 제목 내 세포를 갖고 싶어

명명와 각 셀을 가지고 있지만 그것은 내가 두 차원 배열을 사용하려고하지만 실제로 구현하는 방법을 몰랐다 모든 에 대해 같은 표시 유지하기 위해 어떻게UICollectionViewCell : 다른는

어떤 도움은 매우

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) 

    } 


} 

답변

1

어디 선가 코드에서 당신이 collectionViewCell을 dequeueing되어 있다고 가정을 이해할 수있을 것이다. 셀에서 대기열을 제거한 직후 레이블을 설정할 수 있습니다.

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 
}