CollectionView не отображается вертикально, как ожидалось - PullRequest
1 голос
/ 25 мая 2020

Я пытаюсь реализовать следующий экран.

Expected Output

Но в моем коде он отображается следующим образом:

My Output

следующий код, который я написал,

    import UIKit

class LunchViewController: UIViewController {

    @IBOutlet weak var mainCollectionView: UICollectionView!

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }


}

extension LunchViewController:UICollectionViewDataSource,UICollectionViewDelegateFlowLayout,UICollectionViewDelegate {


    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        return CGSize(width: 412, height: 180)
    }


    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
       // return self.myLibraryArray.count
        return 8
    }

    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

        // let item = self.myLibraryArray[indexPath.row]

        guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "RestaurantCollectionViewCell", for: indexPath) as? RestaurantCollectionViewCell else {
            return UICollectionViewCell()
        }
        //cell.fillDetails(item)
        return cell

    }


}

Вот полная ссылка на проект

Кто-нибудь может мне сказать , в чем проблема? или что мне нужно написать код, чтобы получить ожидаемый результат?

Обновление :

some white Seperator is showing

Ответы [ 2 ]

2 голосов
/ 25 мая 2020

Выберите collectionView и измените размер оценки на none. В раскадровке. если вам не нужно пространство между двумя ячейками, установите 0 на for lines в Min spacing

enter image description here

И я дал width как ширина экрана

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
    return CGSize(width: UIScreen.main.bounds.size.width, height: 180)
}

Вывод: -

enter image description here

2 голосов
/ 25 мая 2020

Измените метод sizeForItem на этот:

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
    return CGSize(width: collectionView.frame.size.width, height: 180)
}

Также убедитесь, что mainCollectionView ограничен передним и задним краями в раскадровке.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...