I have UICollectionViewCell
s that have only one UIImageView
. I am using RxSwift
for the project. The delegate
is set in the Main.storyboard
, and the datasource
is set by the RxSwift
. I need to remove the spaces between the cells, but having trouble with that. The methods from this thread are not working:
Aligning collection view cells to fit exactly 3 per row
I tried both answers but nothing happens.
Here is the UIViewCollectionController
s' code:
let disposeBag = DisposeBag()
override func viewDidLoad() {
super.viewDidLoad()
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false
// Register cell classes
//self.collectionView!.register(UICollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier)
// Do any additional setup after loading the view.
collectionView?.dataSource = nil
setupCellConfiguration()
}
private func setupCellConfiguration() {
//1
immuneCells
.bind(to: self.collectionView!
.rx //2
.items(cellIdentifier: CellTypeCollectionViewCell.Identifier,
cellType: CellTypeCollectionViewCell.self)) { // 3
row, cellType, cell in
cell.configureWithCellType(cellType: cellType) //4
}
.disposed(by: disposeBag) //5
}
override func numberOfSections(in collectionView: UICollectionView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of items
let num = CellType.immune.count
return num
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let screenWidth = UIScreen.main.bounds.width
let scaleFactor = (screenWidth / 3) - 6
return CGSize(width: scaleFactor, height: scaleFactor)
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
return UIEdgeInsets.zero
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
return 0
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
return 0
}
Any suggestions would be greatly appreciated
Update
I tried setting up equal width and height, top, left constraints of UIImageView
but it did not help.
This is how it looks:
Try
flowLayout.minimumLineSpacing = 0
flowLayout.minimumInteritemSpacing = 0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With