iOS collectionView的headerView,重

2023-11-13  本文已影响0人  可乐小子

func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {

    let headerView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: headerViewCellID, for: indexPath) as UICollectionReusableView
    var  nameLabel = headerView.viewWithTag(9999)
    if let nameLabel = nameLabel {
        var  nameLab = nameLabel as! UILabel
        nameLab.text = sectionArray[indexPath.section]
    } else {
        
      var  secondLabel : UILabel = UILabel.init(frame: CGRectMake(16, 24, 100, 18))
        secondLabel.tag = 9999
        
        secondLabel.textAlignment = .left
        headerView.addSubview(secondLabel)
        secondLabel.text = sectionArray[indexPath.section]
    }
   
    
    return  headerView
}
上一篇 下一篇

猜你喜欢

热点阅读