【发布时间】:2017-08-14 08:59:29
【问题描述】:
我想每次都创建一个 5*8 矩阵的 UICollectionView。 (表示 5 行和 8 列)适用于所有 iphone 屏幕。 而 Collectionview 约束是:
导致superview = 10
到 superview = 10
顶部到超级视图 = 90
从底部到超级视图 = 150
集合视图结果应该显示如下:
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath as IndexPath) as! NavigateCollectionViewCell
cell.questionLbl.text = items[indexPath.row] as? String
cell.backgroundColor = UIColor.cyan
return cell
}
// MARK: - UICollectionViewDelegate protocol
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
// handle tap events
print("You selected cell #\(indexPath.item)!")
}
请帮忙解决这个问题。
【问题讨论】:
-
self.view.frame.size.width(带空格) / 5
-
你尝试了什么?听起来您刚刚提出了规范,并且希望有人为您提供代码。
-
如果您要发布代码,请尝试使其与问题相关。获取单元格和处理选择的方法与集合视图中单元格的布局无关,这就是您的问题。
标签: ios swift swift3 uicollectionview