请检查此附加代码并缩短屏幕。当我设置容器视图的颜色时它工作正常,但是当我在单元格中添加 UIImage 时它不起作用。我更改了 imageview 内容模式,但它不起作用。
class ViewController: UIViewController {
@IBOutlet weak var segColumn: UISegmentedControl!
@IBOutlet weak var collectionView: UICollectionView!
fileprivate var items: [UIImage] = [ // My images ]
override func viewDidLoad() {
super.viewDidLoad()
self.setup()
}
}
extension ViewController: UICollectionViewDataSource{
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return items.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! CollectionViewCell
cell.imgCell.image = items[indexPath.row]
cell.imgCell.contentMode = .scaleAspectFill
cell.contentView.backgroundColor = …Run Code Online (Sandbox Code Playgroud) uiimageview uiimage uicollectionview uicollectionviewlayout swift