How to set the collection view cell size exactly equal to the collection view in iOS?

后端 未结 3 2028
梦毁少年i
梦毁少年i 2021-01-20 01:01

I want to set a collection view where it is only displayed one element at the time and it scrolls horizontally. I want to know how to set the same size for both if the colle

3条回答
  •  春和景丽
    2021-01-20 01:51

    if you want to add it programmatically you can try this:

    lazy var collectionView: UICollectionView = {
            let layout = UICollectionViewFlowLayout()
            layout.scrollDirection = .horizontal
            layout.minimumLineSpacing = 0
            let cv = UICollectionView(frame: .zero, collectionViewLayout: layout)
            cv.backgroundColor = .white
            cv.delegate = self
            cv.dataSource = self
            cv.isPagingEnabled = true
            cv.showsHorizontalScrollIndicator = false
            return cv
    }()
    

提交回复
热议问题