我的CollectionView
中有12个单元格。我想像这样在一个屏幕上显示3个单元格:
并向右滚动以显示另一个单元格。
但是现在我创建了CollectionView
和CollectionViewCell
并在storyboard
中编辑单元格,我得到了以下结果:
如何解决?
我在CollectionView
中的代码:
import UIKit
private let reuseIdentifier = "Cell"
class MasterViewController: UICollectionViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
override func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1
}
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 12
}
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as! MasterViewCell
cell.label.text = String(indexPath.row)
cell.backgroundColor = UIColor.green
return cell
}
}
我在CollectionViewCell
中的代码:
import UIKit
class MasterViewCell: UICollectionViewCell {
@IBOutlet weak var label: UILabel!
}
答案 0 :(得分:0)
答案 1 :(得分:0)