我正在尝试构建一个演示应用程序(对我的技能进行培训)
该演示应用程序有一个垂直的集合视图屏幕,其中包含具有图像视图的单元格 和带标签的视图
布局原样 - 每个单元150宽度和415高度每行2个单元格垂直移动
我想让每个单元格在imageView内的图像上处于不同的单元格高度,然后我想确保每个单元格都粘在它上面的单元格中
当我尝试这样做时,我设法按比例更改单元格大小,但我无法更改单元格Y位置
无论如何,我的整个代码希望你们明白我的意思,非常感谢
import UIKit
class ViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
var imagesArray = [#imageLiteral(resourceName: "Forest"),#imageLiteral(resourceName: "Tree") , #imageLiteral(resourceName: "hinna"), #imageLiteral(resourceName: "beach1"),#imageLiteral(resourceName: "work"),#imageLiteral(resourceName: "ya"),#imageLiteral(resourceName: "bird"),#imageLiteral(resourceName: "rose"),#imageLiteral(resourceName: "Tree"),#imageLiteral(resourceName: "Labra") ]
var labelsArray = ["bahwaijf", "abwohd", "owauhduo", "awodh"]
@IBOutlet weak var collectionView: UICollectionView!
override func viewDidLoad() {
super.viewDidLoad()
self.collectionView.delegate = self
self.collectionView.dataSource = self
}
public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return imagesArray.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! CollectionVCe
cell.cellImg.image = imagesArray[indexPath.row]
cell.descLabel.text = descArray[indexPath.row]
cell.itemLabel.text = labelsArray[indexPath.row]
return cell
}
}