ฉันมี UICollectionView ที่เลื่อนในแนวนอนและฉันต้องการให้เซลล์หนึ่งเซลล์ปรากฏบนหน้าจอในแต่ละครั้ง
ฉันกำลังตั้งค่าความกว้างและความสูงของเซลล์โดยทางโปรแกรมโดยใช้วิธีต่อไปนี้:
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath as IndexPath) as! Cell
let width = collectionView.bounds.size.width - 40
let height = collectionView.bounds.size.height - 40
cell.bounds.size = CGSize(width: CGFloat(width), height: CGFloat(height))
return cell
}
และหลังจากดิ้นรนเพื่อหาวิธีทำงานกับสิ่งที่แทรก การเว้นวรรค ส่วนแทรก (ทั้งทางโปรแกรมและในตัวตรวจสอบใน XCode) ดูเหมือนว่าฉันไม่สามารถเข้าใจได้ว่าต้องตั้งค่าอะไรและต้องตั้งค่าที่ไหน