1在这个方法中返回cell
func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
if kind == UICollectionView.elementKindSectionFooter {
let reusableview = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "collectionFooter", for: indexPath) as! CollectionViewFooterView
reusableview.finishBtn.addTarget(self, action: #selector(finishBtnClick), for: .touchUpInside)
reusableview.changeBtn.addTarget(self, action: #selector(changeBtnClick), for: .touchUpInside)
if(self.age.count > 0 && self.sex.count > 0 && self.selectContentArray.count > 0){
reusableview.finishBtn.backgroundColor = .red
reusableview.finishBtn.isEnabled = true
}else{
reusableview.finishBtn.backgroundColor = .gray
reusableview.finishBtn.isEnabled = false
}
return reusableview
}else{
return UICollectionReusableView()
}
}
2 设置宽高
layout.footerReferenceSize = CGSize(width: ScreenSize.SCREEN_WIDTH, height: 80)
3 注册自定义footer
collectionView.register(CollectionViewFooterView.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionFooter, withReuseIdentifier: "collectionFooter")