这个错误:
索引路径中补充项的布局属性已更改,但未更改
使布局无效。
是为 FooterView
设置布局的原因
所以你必须为 View
做
Layout
这是我的 CollectionView
的示例
let historyCollection: UICollectionView = {
let layout = UICollectionViewFlowLayout()
layout.sectionInset = UIEdgeInsets(top: 0, left: 0, bottom: 10, right: 0)
layout.minimumInteritemSpacing = 0
layout.minimumLineSpacing = 20
layout.scrollDirection = .vertical
let historyCollection = UICollectionView(frame: CGRect.zero, collectionViewLayout: layout)
historyCollection.register(CodiHistoryCell.self, forCellWithReuseIdentifier: "history")
historyCollection.register(fooderSection.self, forSupplementaryViewOfKind: UICollectionElementKindSectionFooter, withReuseIdentifier: "footer")
historyCollection.isScrollEnabled = true
historyCollection.backgroundColor = UIColor.clear
historyCollection.translatesAutoresizingMaskIntoConstraints = false
return historyCollection
}()
所以在你命名你的标识符之后
UICollectionElementKindSectionFooter, withReuseIdentifier: "footer"
您必须将它的内容放在我在控制器类中所做的“FooterView”中
import UIKit
class fooderSection: UICollectionReusableView {
let checkBtn: UIButton = {
let checkBtn = UIButton(type: .custom)
checkBtn.setImage(UIImage(named: "loadMoreIcon"), for: .normal)
checkBtn.contentMode = UIView.ContentMode.scaleAspectFit
checkBtn.translatesAutoresizingMaskIntoConstraints = false
return checkBtn
}()
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override init(frame: CGRect) {
super.init(frame: frame)
self.addSubview(checkBtn)
//this is how it's going to show in the bottonVIEW
just play while this values
NSLayoutConstraint.activate([
checkBtn.centerXAnchor.constraint(equalTo: self.centerXAnchor),
checkBtn.centerYAnchor.constraint(equalTo: self.centerYAnchor),
checkBtn.widthAnchor.constraint(equalToConstant: 70),
checkBtn.heightAnchor.constraint(equalToConstant: 70)
])
}
}
您还必须为 FooterView 设置 reference 大小
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForFooterInSection section: Int) -> CGSize {
return CGSize(width: view.frame.width, height: interface.frame.height * 0.1)
}