在CollectionView的末尾添加ImageView

时间:2016-12-14 16:08:45

标签: ios swift uiimageview uicollectionview

我使用Storyboards创建了一个CollectionViewController并通过代码进行了调整,现在我需要在屏幕底部添加一个ImageView,它占据视图的整个宽度。

我尝试使用Storyboard来实现它,但它没有用,如果我以编程方式添加它,我应该在哪里以及如何进行呢?

import UIKit
import Device_swift

class MenuCentralCollectionViewController: UICollectionViewController {


    //data source

    let deviceType = UIDevice.current.deviceType



    // MARK: ViewController life cycle

    override func viewDidLoad() {
        super.viewDidLoad()

        let layout = collectionViewLayout as! UICollectionViewFlowLayout
        layout.itemSize = CGSize(width: 310 / 2 - 37.5, height: 150)
    }

    // MARK: - UICollectionviewDataSource

    override func numberOfSections(in collectionView: UICollectionView) -> Int {
        return 1
    }

    override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 8
    }

    private struct Storyboard {
        static let CellIdentifier = "MenuCell"
    }

    override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: Storyboard.CellIdentifier, for: indexPath) as UICollectionViewCell

        return cell
    }

1 个答案:

答案 0 :(得分:1)

使用UIViewController并自行添加UICollectionView作为子视图。使用这种方法,您可以添加任何帧的任何子视图,而不仅仅是全屏`UICollectionView。

相关问题