【发布时间】:2021-06-26 00:43:12
【问题描述】:
我正在尝试制作一个显示水晶图像的程序。编写代码并格式化 StoryBoard 后,当我运行应用程序时,图像很小并且没有显示任何标签。我有限制。
代码如下:
import UIKit
class ViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource {
let imageArray = [UIImage(named: "1"),UIImage(named: "2"),UIImage(named: "3")]
let nameArray = ["Rose Quartz", "Clear Quartz", "Clear Quartz 2"]
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return imageArray.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "MainCollectionViewCell", for: indexPath) as! MainCollectionViewCell
cell.crystalPhotoImageView.image = imageArray[indexPath.row]
cell.crystalNameLabel.text! = nameArray[indexPath.row]
return cell
}
}
【问题讨论】:
-
我现在在单元格的大小检查器中取消选择了“内容视图”,现在一切都变得巨大了,哈哈。还在折腾……
-
你是否在可选的 func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize中设置了collectionView单元格的大小
-
在 UICollectionView 的 Size Inspector 中将“Estimate Size”更改为“None”并修复了它!
标签: ios swift iphone xcode uicollectionview