ios - 我的 collectionView 中的页 footer 分出现问题

标签 ios swift uicollectionview

我正在尝试在我的 collectionView 中实现自定义页 footer 分,但我想我遗漏了一些东西。我要存档我的代码。我希望你能帮助我。

谢谢!!!

自定义页 footer 分

class FooterCell: UICollectionViewCell {

let etiqueta: UILabel = {
    let label = UILabel()
    label.backgroundColor = .green
    label.translatesAutoresizingMaskIntoConstraints = false
    return label
}()

override init(frame: CGRect) {
    super.init(frame: frame)

    addSubview(etiqueta)

    etiqueta.topAnchor.constraint(equalTo: self.topAnchor).isActive = true
    etiqueta.rightAnchor.constraint(equalTo: self.rightAnchor).isActive = true
    etiqueta.widthAnchor.constraint(equalToConstant: 50).isActive = true
    etiqueta.heightAnchor.constraint(equalToConstant: 50).isActive = true
}

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

Collection View 类

override func viewDidLoad() {
    super.viewDidLoad()


    collectionView?.register(FooterCell.self, forSupplementaryViewOfKind: UICollectionElementKindSectionFooter, withReuseIdentifier: "Footer") }

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

    var reusableView = FooterCell()



    if kind == UICollectionElementKindSectionFooter {

        reusableView = collectionView.dequeueReusableSupplementaryView(ofKind: kind,  withReuseIdentifier: "Footer", for: indexPath) as! FooterCell

        reusableView.etiqueta.backgroundColor = .green
    }

    return reusableView

}

最佳答案

添加此方法-:

optional func collectionView(_ collectionView: UICollectionView, 
                  layout collectionViewLayout: UICollectionViewLayout, 
                  referenceSizeForFooterInSection section: Int) -> CGSize

关于ios - 我的 collectionView 中的页 footer 分出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45000181/

相关文章:

ios - 如何在 UITableView 单元格中创建自定尺寸网格?

ios - 如何在 Collection View 中自动选择可见的项目? swift 4

ios - 如何在 View 加载时设置 UITableView 的滚动位置?

ios - 删除链接到锻炼的所有数据样本

iphone - iOS 4+ : Need App to send multiple Emails with Attachments but LATER, 不是立即

swift 3 : Watch app: if watch goes to sleep there's a delay between interface controllers

ios - swift 中白色背景图像上的白色文本

ios - 如何从 UICollectionViewCell 访问 UICollectionView 中 Cell 的 indexPath

ios - 显示键盘时禁用按钮

ios - 模仿 iOS 横幅样式通知/应用内导航的功能