【发布时间】:2017-05-07 11:16:04
【问题描述】:
我正在尝试构建一个演示应用程序(我的技能培训)
该演示应用有一个垂直的集合视图屏幕,其中包含带有图像视图的单元格 和一个带标签的视图
布局原样 - 每个单元格 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
}
}
【问题讨论】:
标签: ios swift layout uicollectionview