【发布时间】:2017-08-08 22:16:55
【问题描述】:
代码:
let reuseIdentifier = "cell"
var items = ["1", "2", "3", "4","5","6","7","8", "9", "10", "11","12","13","14"]
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return self.items.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath as IndexPath) as! MyCollectionViewCell
// Use the outlet in our custom class to get a reference to the UILabel in the cell
cell.myLabel.text = self.items[indexPath.item]
cell.backgroundColor = UIColor.red
return cell
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: CGFloat((collectionView.frame.size.width / 2) - 8), height: CGFloat(250))
}
【问题讨论】:
-
图片不可见
-
可以贴截图吗?
-
您应该解释您遇到的问题并展示您尝试解决的问题。水平轴上有多余的空间吗?纵轴?细胞之间?部分之间?请详细说明,以便您可以帮助我们。
-
@ShyamShukla :将您的屏幕截图上传到imgur.com 等图片上传网站并在此处分享链接。
-
我的截图链接在这里。ibb.co/jeXYov
标签: ios iphone swift uicollectionview