I am using this code to get correct type but not getting the view what i want can any one tell me where am i wrong
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
screenSize = UIScreen.main.bounds
screenWidth = screenSize.width
screenHeight = screenSize.height
videosCollectionView.delegate = self
videosCollectionView.dataSource = self
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 4
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = videosCollectionView.dequeueReusableCell(withReuseIdentifier: "Videos", for: indexPath as IndexPath) as! VideosCollectionViewCell
cell.mainImgVw.image = logoImage[indexPath.row]
cell.durationLabel.text = "duration"
cell.nameLabel.text = "Test Video"
return cell
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let xPadding = 10
let spacing = 10
let rightPadding = 10
let width = (CGFloat(UIScreen.main.bounds.size.width) - CGFloat(xPadding + spacing + rightPadding))/2
let height = CGFloat(215)
return CGSize(width: width, height: height)
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
return UIEdgeInsetsMake(10, 10, 10, 10)
}
Please tell me where i am wrong. Please help me.
Try this :-
Hope it will help you
Declare
UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout
Set min space for cell and for line from storyboard like this.
Set collectionview cell width like this,
As you have told that you want to use collectionViewFlowDelegateLayout. So, you have to set all values 0 from storyboard as I have shown below.
Then you have to write this code in your viewcontroller class.
This method is used for set the cell size in collection view.
This method is used for the margins to apply to content in the specified section.
This method is used for spacing between successive rows or columns of a section.
Your code works fine and there isn't any problem, check
Min Spacing
inSize Inspector
tab it should be too large, set it 10