[英]Add ImageView @ the end of a CollectionView
I created a CollectionViewController using Storyboards and made the adjustments by code and now I need to add a ImageView at the bottom of the screen that takes the whole width of the view. 我使用情节提要板创建了一个CollectionViewController,并通过代码进行了调整,现在我需要在屏幕底部添加一个ImageView,以占据视图的整个宽度。
I tried using Storyboards to do it, but it didn't work, if I add it programmatically, where and how should I do it? 我尝试使用情节提要(Storyboards)来执行此操作,但是如果我以编程方式添加它,则该操作不起作用,应该在哪里以及如何执行?
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
}
Use UIViewController
and add UICollectionView
as subview yourself. 使用UIViewController
并将UICollectionView
添加为自己的子视图。 With this approach you can add any subviews with any frames, not only fullscreen `UICollectionView. 使用这种方法,您可以添加具有任何框架的任何子视图,而不仅仅是全屏`UICollectionView。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.