我正在尝试使用一个收集视图来显示一系列客户推荐。我在内容视图上有另一个收集视图,这就是为什么下面的代码部分合并了图像收集视图的原因。该应用程序可以在我的手机上正常运行,但标签不会显示在屏幕上。我在做什么错?
@IBOutlet weak var collectionViewTwo: UICollectionView!
let testimonialArray = ["You rock", "You suck"]
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if collectionView.tag == 1 {
let cell = collectionViewOne.dequeueReusableCell(withReuseIdentifier: "HomeOneCollectionViewCell", for: indexPath) as? HomeOneCollectionViewCell
cell!.imageOne.image = imageArrayOne[indexPath.row]
return cell!
} else {
let cell = collectionViewTwo.dequeueReusableCell(withReuseIdentifier: "HomeTwoCollectionViewCell", for: indexPath) as? HomeTwoCollectionViewCell
cell?.testimonialLabel?.text = testimonialArray[indexPath.row]
cell?.testimonialLabel?.textColor = UIColor.white
return cell!
}
}
猜测您错误地将文本颜色设置为白色吗?白色标签不会在白色背景上显示。注释该行应显示结果。 PFA。
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if collectionView.tag == 1 {
let cell = collectionViewOne.dequeueReusableCell(withReuseIdentifier: "HomeOneCollectionViewCell", for: indexPath) as? HomeOneCollectionViewCell
cell!.imageOne.image = imageArrayOne[indexPath.row]
return cell!
} else {
let cell = collectionViewTwo.dequeueReusableCell(withReuseIdentifier: "HomeTwoCollectionViewCell", for: indexPath) as? HomeTwoCollectionViewCell
cell?.testimonialLabel?.text = testimonialArray[indexPath.row]
// cell?.testimonialLabel?.textColor = UIColor.white
return cell!
}
}