美文网首页
iOS collectionView的headerView,重

iOS collectionView的headerView,重

作者: 可乐小子 | 来源:发表于2023-11-13 13:14 被阅读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
    }

    相关文章

      网友评论

          本文标题:iOS collectionView的headerView,重

          本文链接:https://www.haomeiwen.com/subject/lpcdwdtx.html