答案 0 :(得分:0)
这可以使用UICollectionView
footerView实现。下面是一个可能如何工作的示例:
首先,在ViewDidLoad
中注册页脚视图类:
override func viewDidLoad() {
super.viewDidLoad()
registerClass(myFooterViewClass, forSupplementaryViewOfKind: UICollectionElementKindSectionFooter, withReuseIdentifier: "Footer")
}
第二,在headerReferenceSize
中设置collectionViewFlowLayout
或在collectionView:layout:referenceSizeForHeaderInSection:
中实现UICollectionViewDelegate
。
第三,从dataSource
返回footerView:
func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView {
let view = collectionView.dequeueReusableSupplementaryViewOfKind(UICollectionElementKindSectionFooter, withReuseIdentifier: "myFooterView", forIndexPath: indexPath)
// Add your button here
return view
}
答案 1 :(得分:0)
extension ViewController: UICollectionViewDataSource {
func numberOfSections(in collectionView: UICollectionView) -> Int {
return 5
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 1
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if indexPath.section != 5 {
//without button Cell
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: contentCellIdentifier, for: indexPath) as! CollectionViewCell
return cell
} else {
//with button Cell like setting Click
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: contentCellIdentifier, for: indexPath) as! CollectionViewCell
return cell
}
}
}
extension ViewController:UICollectionViewDelegate,UICollectionViewDelegateFlowLayout{
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
if indexPath.section == 5 {
//open your viewController in which you want to setting view like.
}
}
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
return CGSize(width: screenWidth/2, height: screenWidth/3);
}
}