0
私はこのようなカスタムセルを作りたい:ここカスタムCollectionViewレイアウト
が私のコードです:
import UIKit
class ViewController: UIViewController, UICollectionViewDelegateFlowLayout, UICollectionViewDataSource {
@IBOutlet var collectionView: UICollectionView!
override func viewDidLoad() {
super.viewDidLoad()
collectionView.delegate = self
collectionView.dataSource = self
}
func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 1
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 3
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("ImageCollectionViewCell", forIndexPath: indexPath) as! ImageCollectionViewCell
if indexPath.row == 0 {
cell.imgView.image = UIImage(named: "1")
} else if indexPath.row == 1 {
cell.imgView.image = UIImage(named: "2")
} else {
cell.imgView.image = UIImage(named: "3")
}
return cell
}
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
let screenWidth = UIScreen.mainScreen().bounds.width
if indexPath.row == 0 {
return CGSize(width: screenWidth/2, height: screenWidth)
} else if indexPath.row == 1 {
return CGSize(width: screenWidth/2, height: screenWidth/2 - 20)
} else {
return CGSize(width: screenWidth/2, height: screenWidth/2 - 20)
}
}
}
は私のコードを持つ任意の間違っありますか?
ありがとうございます。私はそれをチェックします。 – Khuong